I’m trying to include the Google graph api in my Drupal 7 module (not the google graph module). But when I try to call upon the service I get:
- “attempt to run compile-and-go script on a cleared scope” – error in
Firefox. - “Could not send response: Cannot send a response more than once per
chrome.extension.onRequest listener per document” -error in Chrome.
Code is as follows:
(function ($) {
Drupal.behaviors.exampleModule = {
attach: function (context, settings) {
// 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);
}
alert("test");
}
};
})(jQuery);
What can I do to get this to work ?
-Thanks
I fixed it:
The
google.load('visualization', '1.0', {'packages':['corechart']});line should be called first, just after(function ($) {. so the solution is :