Reputation: 17
This is the last part of my code for Google Charts:
array.push("['" + tbl.rows[k].cells[l-1].innerHTML + "', " + tbl.rows[k].cells[l+10].innerHTML + "]");
}
}
//alert(array);
var data = new google.visualization.DataTable();
// Declare columns
data.addColumn('string', 'boxes');
data.addColumn('number', 'price');
// Add data.
data.addRows([
['box1', 10.42],['box2', 14.77],['box3', 9.75],['box4', 1.43]
//I put it manually and works. But If I type "array", does not work.
]);
// Set Options
var options = {
title: 'Boxes (f) Prices',
hAxis: {title: 'kind of boxes'},
vAxis: {title: 'prices ($)'},
};
// Draw
var chart = new google.visualization.LineChart(document.getElementById('myChart'));
chart.draw(data, options);
}
As you can see, the array is not the same every time. At this particular time "alert(array);" gave this:
['box1', 10.42],['box2', 14.77],['box3', 9.75],['box4', 1.43]
I copy-paste it and the code works fine. But that's where I want the final result of "array.push" to go. Ιf I type "array", the code does not work. What is the solution?
Upvotes: 1
Views: 64
Reputation: 61222
first, just build a normal array, no need to use string concatenation, here...
array.push([tbl.rows[k].cells[l-1].innerHTML, parseFloat(tbl.rows[k].cells[l+10].innerHTML)]);
then when you want to add to the datatable...
data.addRows(array);
Upvotes: 1