谷歌图表Javascript文字数据表示法给出;“不是数组”;错误
当将Javascript文字数据与Google Charts ArrayTable函数结合使用时,它会在Javascript中返回一个错误,在Modernizer-3.5.2.js文件的第行中声明“不是数组” 433->谷歌图表Javascript文字数据表示法给出;“不是数组”;错误,javascript,charts,google-visualization,syntax-error,Javascript,Charts,Google Visualization,Syntax Error,当将Javascript文字数据与Google Charts ArrayTable函数结合使用时,它会在Javascript中返回一个错误,在Modernizer-3.5.2.js文件的第行中声明“不是数组” 433->ret=!!(window.WebGLRenderingContext&&(canvas.getContext('experimental-webgl')| | canvas.getContext('webgl')) 你知道为什么吗?数据对象是按照GoogleChartAPI文档
ret=!!(window.WebGLRenderingContext&&(canvas.getContext('experimental-webgl')| | canvas.getContext('webgl'))代码>
你知道为什么吗?数据对象是按照GoogleChartAPI文档状态生成的
生成图表的代码如下所示:
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);
什么是JsonChartData?没有相关内容。从代码粘贴到此处时出错。我现在更正了上面的代码,所以它是有意义的。实际上,ChartData1是在函数StackedColumnChart之外生成的,并作为函数参数传入。为了演示,我简化了它。