“尝试在清除的范围内运行编译和运行脚本” - 使用 Google Graph API 在 Drupal 中出错
"attempt to run compile-and-go script on a cleared scope" - Error in Drupal with Google Graph api
我正在尝试将Google graph api包含在我的Drupal 7模块(不是Google Graph模块)中。但是当我尝试调用服务时,我得到:
- "尝试在清除的作用域上运行编译和运行脚本" - 错误火狐。
- "无法发送响应:无法按chrome.extension.onRequest listener per document" -error in Chrome.
代码如下:
(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);
我能做些什么来让它工作?-谢谢
我修复了它:
google.load('visualization', '1.0', {'packages':['corechart']});
行应该先调用,紧接着(function ($) {
。 所以解决方案是:
(function ($) {
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
Drupal.behaviors.exampleModule = {
attach: function (context, settings) {
// 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);
相关文章:
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- 在gwt HTMLPanel中使用JavaScript运行Google图表
- 在HTML JavaScript头部分运行Google脚本函数
- 在 Google Compute Engine Debian 服务器上运行 Node.js
- 当运行Google“;Hello Analytics"API教程
- 仅通过最后一行运行Google脚本
- 确定 Google 地图 API 在运行时是否使用了无效密钥
- 有没有办法将Google Analytics for Web置于“试运行”模式,例如GA移动SDK
- Google Chrome Jquery onSelect 不会运行
- 从Chrome Extension运行Google Apps脚本
- 阻止 Google App 运行的 JavaScript 行
- Google Apps 脚本在保护多个范围时运行时间非常慢
- “尝试在清除的范围内运行编译和运行脚本” - 使用 Google Graph API 在 Drupal 中出错
- 在应用程序代码上运行Google Closure编译器后,更新AngularJS模板HTML
- 为什么不alert((parseInt(“3”))++);在Google Chrome中运行
- 有没有办法在脚本所有者的授权下运行google docs脚本?
- 仅当表单完成时才运行.google.script
- 在运行Google' Javascript Maps API时可能存在哪些限制?
- 为什么通过Grunt运行Google JavaScript Linter会失败
- 在iframe中运行Google Analytics