addColumn Error

205 views
Skip to first unread message

Tday

unread,
Oct 12, 2011, 1:48:00 PM10/12/11
to Google Visualization API
Below is some code that keeps giving me errors.

var data2 = google.visualization.DataTable();
data2.addColumn('string', 'API Name');
data2.addColumn('string', 'Status');
data2.addRows([
['API Name','Status'],
['*****','*****************']
]);

I keep getting the error Cannot call method 'addColumn' of undefined.

I starred out the data in my rows (there are a lot more in the actual
code) as the data is somewhat confidential/protected.

I'm about ready to pull out my hair with this. I see no discernable
differences in syntax between this and the working samples google
provides (such as this: http://code.google.com/apis/chart/interactive/docs/quick_start.html)

asgallant

unread,
Oct 12, 2011, 2:05:09 PM10/12/11
to google-visua...@googlegroups.com
I typically see this when one of two things happens: 1) the script doesn't load the visualization API properly, or 2) the script doesn't wait for the API to finish loading before trying to use it.  Make sure you have it set up something like this:

google.load('visualization''1'{packages['corechart']});
google.setOnLoadCallback(drawVisualization);
function drawVisualization({
   // create and draw the visualization
}

Tim Day

unread,
Oct 12, 2011, 2:16:14 PM10/12/11
to google-visua...@googlegroups.com
Well, I'm at a loss--I have literally the exact.  Same.  Thing.  That's what I was thinking, the package must have loaded improperly.  Here's the whole script if it helps.

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

    // Load the Visualization API and the controls package.

google.load('visualization', '1.0', {packages:['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);

    // Main function
    function drawChart() {
// Data
var data = google.visualization.DataTable();
data.addColumn('string', 'API Name');
data.addColumn('number', 'Status');
data.addRows([
['API Name','Status'],
['Login',1],
['TVOD',2],
['Headends',3],
['Channel',4]
]);
var options = {'title':'API Status',
'width':400,
'height':300};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data,options);
}
</script>  

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/Qoaa007Z4VEJ.

To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.



--
Haikus are easy
But sometimes they don't make sense
Refrigerator

Tim Day

unread,
Oct 12, 2011, 2:23:43 PM10/12/11
to google-visua...@googlegroups.com
Oh, right--I did change it a little bit.  I wanted to make it as close as I could.  I changed it to a string and number as opposed to two string columns.

asgallant

unread,
Oct 12, 2011, 2:39:34 PM10/12/11
to google-visua...@googlegroups.com
You are missing the 'new' keyword in the dataTable declaration.  It should be:

var data new google.visualization.DataTable();

Also, the first row of data you are adding (['API Name','Status'],) will throw an error, as you need to match data types (in this case, the second value should be a string), but your initial code would have been correct here.

Tim Day

unread,
Oct 12, 2011, 2:43:35 PM10/12/11
to google-visua...@googlegroups.com
At least it wasn't something silly... 

*facepalm*

Thanks!  That fixed it.


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
Reply all
Reply to author
Forward
0 new messages