Google Charts Javascript 文字数据表示法给出“Not a array”错误
Google Charts Javascript Literal data notation gives "Not an array" error?
当将Javascript文字数据与Google Charts arrayToTable函数结合使用时,它会在Javascript中返回一个错误,该错误在Modernizr-3.5.2.js文件中指出"不是数组"433-> ret = !!(window.WebGLRenderingContext && (canvas.getContext('experimental-webgl') || canvas.getContext('webgl')));
任何想法为什么?数据对象是按照谷歌图表API文档状态生成的。
生成图表的代码如下:
google.load("visualization", "1", { packages: ["corechart"] });
function StackedColumnChart(ChartDivContainerID) {
var ChartData1 = {
cols: [{ id: 'Genre', label: 'Genre', type: 'string' },
{ id: 'Fantasy & Sci Fi', label: 'Fantasy & Sci Fi', type: 'number' },
{ id: 'Romance', label: 'Romance', type: 'number' },
{ id: 'Mystery/Crime', label: 'Mystery/Crime', type: 'number' },
{ id: 'General', label: 'General', type: 'number' },
{ id: 'Western', label: 'Western', type: 'number' },
{ id: 'Literature', label: 'Literature', type: 'number' }
],
rows: [{ c: [{ v: '2010' }, { v: 10 }, { v: 24 }, { v: 20 }, { v: 32 }, { v: 18 }, { v: 5 }] },
{ c: [{ v: '2020' }, { v: 16 }, { v: 22 }, { v: 23 }, { v: 30 }, { v: 16 }, { v: 9 }] },
{ c: [{ v: '2030' }, { v: 28 }, { v: 19 }, { v: 29 }, { v: 30 }, { v: 12 }, { v: 13 }] }
]
}
var data = google.visualization.arrayToDataTable(ChartData1);
var options = {
width: 600,
height: 400,
legend: { position: 'top', maxLines: 3 },
bar: { groupWidth: '75%' },
isStacked: true,
};
var chart = new google.visualization.ColumnChart(document.getElementById(ChartDivContainerID));
chart.draw(data, options);
}
您的数据对象是正确的,但您正在调用
var data = google.visualization.arrayToDataTable(ChartData1);
而不是
var data = new google.visualization.DataTable(ChartData1);
相关文章:
- 如何为json对象中的段发送array[]
- jQuery is not loaded
- AngularJS JSON not arriving php
- Array.length似乎不起作用;console.log则显示其他情况
- $rootScope not working
- reactRedux is not defined
- 如何迭代Array.prototype函数
- jQuery document.ready not working
- Javascript 新的 Array 和 join() 方法
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- Array.lenght = undefined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript setTimeout for an array
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- node js array.push 'not' working
- Jquery array.push() not working
- Google Charts Javascript 文字数据表示法给出“Not a array”错误
- Why Does typeof array[0] == 'undefined' Not Work?