javascript 当 data.addRows from var

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20840251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:25:56  来源:igfitidea点击:

Google charts "Row given with size different than" when data.addRows from var

javascriptgoogle-visualization

提问by MIkCode

im trying to create bar chart and but for some reason,it dosnt work.

我正在尝试创建条形图,但由于某种原因,它不起作用。

when i copy past data to data.addRows method it working fine but when i insert the data to var rawDataim receiving

当我将过去的数据复制到 data.addRows 方法时它工作正常但是当我将数据插入到var rawData我正在接收

Row given with size different than 8 (the number of columns in the table). 

this is the code:

这是代码:

    data.addColumn('number', 'Time');
    data.addColumn('number', 'a');
    data.addColumn('number', 'b');
    data.addColumn('number', 'c');
    data.addColumn('number', 'd');
    data.addColumn('number', 'e');
    data.addColumn('number', 'f');
    data.addColumn('number', 'g');
    data.addRows([[rawData]]); 

and this is the value of console.log(rawData);

这是console.log(rawData)的值

[8,0,0,0,0,0,0,2],[9,0,0,3,0,1,0,2],[10,0,0,20,0,1,0,7],[11,13,0,24,2,7,0,16],[12,0,1,23,2,3,0,1],[13,2,4,31,2,0,0,6],[14,0,0,53,0,2,0,4],[15,0,1,57,2,2,0,13],[16,0,0,46,0,7,0,6],[17,0,0,61,0,0,0,7],[18,0,0,15,3,2,0,3],[19,0,0,0,1,0,0,182],[21,0,2,0,0,0,0,305],[23,0,0,0,0,6,0,1]

thanks

谢谢

miki

三木

回答by Anto Jurkovi?

rawDatais already defined as array of arrays so you have to call:

rawData已定义为数组数组,因此您必须调用:

data.addRows(rawData); 

instead of

代替

data.addRows([[rawData]]); 

回答by Ashwini Naidu

changing data.addRows([graphcontent[0]]);to data.addRows(graphcontent[0]);fixed the error for me.

改变data.addRows([graphcontent[0]]);data.addRows(graphcontent[0]);固定的错误我。

回答by Parth Modi

rawData is already defined as array so you have to call:

rawData 已经被定义为数组,所以你必须调用:

data.addRows([rawData]);

data.addRows([rawData]);

It should not like data.addRows([[rawData]]); or data.addRows(rawData);

它不应该喜欢data.addRows([[rawData]]); data.addRows(rawData);