Google Charts Examples don't work

2,251 views
Skip to first unread message

Lynn Tran

unread,
Feb 4, 2015, 2:20:17 PM2/4/15
to google-visua...@googlegroups.com
I've copied every sample code from https://developers.google.com/chart/interactive/docs/examples and none of them seem to work. I always get an error.

For example, they have a line that reads:   var data = new google.visualization.DataTable();
And it keeps saying "ReferenceError: "google" is not defined. (line 2, file "Code")


And there just seems to be an error with all the examples. Is it me? Am I doing something wrong?

Sergey Grabkovsky

unread,
Feb 4, 2015, 2:32:53 PM2/4/15
to google-visua...@googlegroups.com
Hi, you're likely forgetting to either include the jsapi script or to do the google.load call (or forgetting to specify your function as a callback to the google load call so that it waits for the charts to load before attempting to draw them). It's really hard to determine exactly where your mistake is without getting a code sample from you, but here is a jsfiddle that you can base your code on: http://jsfiddle.net/walkingeyerobot/aSRUx/

Please note that the jsfiddle example does not have a reference to the jsapi script in the HTML. This is not because it doesn't require jsapi, but because it's hidden away under "External Resources". If you have any more questions (or if I haven't answered this one clearly), please post back with an example of where our charts don't work. We would prefer a jsfiddle, but a full HTML page would work as well.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Lynn Tran

unread,
Feb 4, 2015, 3:05:07 PM2/4/15
to google-visua...@googlegroups.com
Hi Sergey,

I was using that exact sample code, the pizza example. 

I copied the code directly from the website. https://developers.google.com/chart/interactive/docs/basic_load_libs

<html>
 
<head>
   
<!--Load the AJAX API-->
   
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
   
<script type="text/javascript">
   
     
// Load the Visualization API and the piechart package.
      google
.load('visualization', '1.0', {'packages':['corechart']});
     
     
// Set a callback to run when the Google Visualization API is loaded.
      google
.setOnLoadCallback(drawChart);

     
// Callback that creates and populates a data table,
     
// instantiates the pie chart, passes in the data and
     
// draws it.
     
function drawChart() {

      // Create the data table.

     
var data = new google.visualization.DataTable();

      data
.addColumn('string', 'Topping');
      data
.addColumn('number', 'Slices');
      data
.addRows([
       
['Mushrooms', 3],
       
['Onions', 1],
       
['Olives', 1],
       
['Zucchini', 1],
       
['Pepperoni', 2]
     
]);

     
// Set chart options
     
var options = {'title':'How Much Pizza I Ate Last Night',
                     
'width':400,
                     
'height':300};

     
// Instantiate and draw our chart, passing in some options.
     
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart
.draw(data, options);
   
}
   
</script>
 
</head>

 
<body>
<!--Div that will hold the pie chart-->
   
<div id="chart_div" style="width:400; height:300"></div>
 
</body>
</html>

I am getting a syntax error here:

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



------------


I am putting this directly into google scripts. Is this wrong?

Sergey Grabkovsky

unread,
Feb 4, 2015, 3:11:01 PM2/4/15
to google-visua...@googlegroups.com
Oh. Well there's your problem. If you're using App Scripts, you need to use the Charts service. You can find the API for that here: https://developers.google.com/apps-script/reference/charts/

Lynn Tran

unread,
Feb 4, 2015, 3:37:50 PM2/4/15
to google-visua...@googlegroups.com
Oh! I guess I am confused because I thought UI was deprecated!
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages