我有一个硬编码的JSON对象,我正在传递给google.visualization.DataTable()来创建数据表对象,但似乎出现了问题。我在可视化API中遇到了JS错误:“未捕获的TypeError:undefined不是函数”。这是JSON数据:
var jsonData = {
cols: [
{id: 'date', label: 'Sample Date', type: 'date'},
{id: 'countervalue', label: 'Counter Value', type: 'number'}
],
rows: [
{c: [ {v: Date(2014, 4, 30, 10, 30, 0)}, {v: 2457.0} ] },
{c: [ {v: Date(2014, 4, 30, 10, 30, 15)}, {v: 2458.0} ] },
{c: [ {v: Date(2014, 4, 30, 10, 30, 30)}, {v: 2459.0} ] },
{c: [ {v: Date(2014, 4, 30, 10, 30, 45)}, {v: 2452.0} ] },
{c: [ {v: Date(2014, 4, 30, 10, 31, 0)}, {v: 2451.0} ] },
{c: [ {v: Date(2014, 4, 30, 10, 31, 15)}, {v: 2443.0} ] },
{c: [ {v: Date(2014, 4, 30, 10, 31, 30)}, {v: 2444.0} ] }
]
};
这就是爆炸的地方:
var data = google.visualization.DataTable(jsonData);
这是解决方案的JSFiddle: http://jsfiddle.net/jcaine04/3PJph/2/
答案 0 :(得分:1)
代码工作正常,您只需要更改:
var data = google.visualization.DataTable(jsonData);
要:
var data = new google.visualization.DataTable(jsonData);
此外,将jsfiddle从onLoad更改为noWrap,否则drawChart()
将不会执行。最后,当你修复它会抛出谷歌错误:饼图应该有第一列类型字符串×