[英]Google Charts API: new google.visualization.Table() - Uncaught TypeError: undefined is not a function
I have copied the Google Code example into a php script however I am getting the error "undefined is not a function" 我已将Google Code示例复制到php脚本中但是我收到错误“undefined is not a function”
it is happening specifically on this line: 它发生在这条线上:
var table = new google.visualization.Table(document.getElementById('table_sort_div'));
var table = new google.visualization.Table(document.getElementById('table_sort_div'));
It appeats that the Table function does not exist??? 它表明Table函数不存在???
I have copied the code directly from Googles Code examples so I can't understand what I have done wrong... I'm tending to believe that there is an issue with the example but I'm gonna assume I'd make a mistake before google would? 我直接从谷歌代码示例中复制了代码,所以我无法理解我做错了什么...我倾向于相信这个例子有问题,但我会假设我犯了一个错误谷歌之前会吗?
Code was copied directly from: http://code.google.com/apis/chart/interactive/docs/examples.html#interaction_example 代码直接从以下位置复制: http : //code.google.com/apis/chart/interactive/docs/examples.html#interaction_example
You need to wait for the scripts to load. 您需要等待脚本加载。 For example:
例如:
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['table']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var table = new google.visualization.Table(document.getElementById('table_sort_div'));
}
should work, because the scripts have been loaded. 应该工作,因为脚本已加载。 A better table reference here
这里有更好的表格参考
此外,如果您想加载多个包,您也可以这样做:
google.load('visualization', '1', { packages: ['corechart', 'table'] });
google.charts.load('current', {'packages': ['table']});
google.charts.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time');
data.addRows(5);
data.setCell(0, 0, 'John');
data.setCell(0, 1, 10000, '$10,000');
data.setCell(0, 2, true);
data.setCell(1, 0, 'Mary');
data.setCell(1, 1, 25000, '$25,000');
data.setCell(1, 2, true);
data.setCell(2, 0, 'Steve');
data.setCell(2, 1, 8000, '$8,000');
data.setCell(2, 2, false);
data.setCell(3, 0, 'Ellen');
data.setCell(3, 1, 20000, '$20,000');
data.setCell(3, 2, true);
data.setCell(4, 0, 'Mike');
data.setCell(4, 1, 12000, '$12,000');
data.setCell(4, 2, false);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});
google.visualization.events.addListener(table, 'select', function () {
var row = table.getSelection()[0].row;
alert('You selected ' + data.getValue(row, 0));
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.