I have a page listing in table format some sales data. I want to include a chart. Since I already have to retrieve the data for the table I figured I would also build the array for google and put it in a hidden input to retrieve it with javascript. So this is the javascript
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var chartD = document.getElementById('chartD').value;
var data = google.visualization.arrayToDataTable([chartD]);
var options = {'title':'Sales'};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
This is the input I get the data from
<input type="hidden" id="chartD" value="['Date', 'Units Sold'],
['03-01', 12.00], ['03-04', 32.00], ['03-06', 6.00],
['03-08', 19.00], ['03-11', 10.00], ['03-13', 5.00], ['03-15', 0]">
But when I run this I get an error Not a valid 2D array I then copied the value straight from the view page source like this
var data = google.visualization.arrayToDataTable([['Date', 'Units Sold'],
['03-01', 12.00], ['03-04', 32.00], ['03-06', 6.00], ['03-08', 19.00],
['03-11', 10.00], ['03-13', 5.00], ['03-15', 0]]);
And that worked just fine. Does anyone have any idea what the problem is?