Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  97] [ 4]  / answers: 1 / hits: 16777  / 11 Years ago, mon, june 17, 2013, 12:00:00

I am trying to make a line chart, but Google Charts keeps throwing this error when I try to add a row of data:




Error: Every row given must be either null or an array. @ ...corechart.I.js:162




Here are some example columns I tried. Making the columns works fine, and displays an empty graph as long as I don't add any rows.



var data = new google.visualization.DataTable();
data.addColumn('number', 'timestamp');
data.addColumn('number', 'JPY');
data.addColumn('number', 'EUR');
data.addColumn('number', 'SEK');
data.addColumn('number', 'HKD');
data.addColumn('number', 'CHF');
//So far so good


Now, no matter how I try to pass an array with addRows(), I get the error. I have found similar questions here, but they've all failed for reasons of malformed code or used a different methodology to pass the code in. So here is a simplified test case, which still fails.



data.addRows([1,2,3,4,5,6]); //Breaks the chart


I also tried:



var myrow = new Array(1,2,3,4,5,6);
data.addRows(myrow);


I don't see how I can make this any more literally an array. I also passed two at once, because all the example code seems to pass multiple rows.



data.addRows([1,2,3,4,5,6],
[7,8,9,10,11,12]);


Still fails.


More From » arrays

 Answers
5

Easy one. The addRows() method expects you to provide an array of arrays, not a single array for one row, and not separate parameters for each row. See the example in the docs. Fixing your example, it should look like this:



data.addRows([[1,2,3,4,5,6], [7,8,9,10,11,12]]);


You might also prefer to use the addRow() method, which takes just one row at a time.


[#77582] Saturday, June 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradenc

Total Points: 75
Total Questions: 96
Total Answers: 129

Location: Burundi
Member since Thu, Feb 10, 2022
2 Years ago
;