I have a php script that generates the google chart data and returns it in json encoded format. It's loaded into google chart using jQuery $.get() method. When I pass the return data to the google "arrayToDataTable" function like this:
var googleChartData = google.visualization.arrayToDataTable(chartData);
I get this error:
So, what I did was I dumped the value of my variable "chartData" and I got the following:
So, what I did was, copy this data from console window into the "arrayToDataTable" function manually like this:
var googleChartData = google.visualization.arrayToDataTable([["Date Range","0001\/102\/0 Available","0001\/102\/0 Unavailable","0001\/102\/1 Available","0001\/102\/1 Unavailable"],["02\/10\/2013",0,1,110,11],["03\/10\/2013",0,1,189,11],["04\/10\/2013",0,1,189,11],["06\/10\/2013",0,1,189,10],["07\/10\/2013",0,1,187,10],["08\/10\/2013",186,11,0,1],["09\/10\/2013",186,11,0,1],["10\/10\/2013",0,1,186,11],["11\/10\/2013",0,1,204,11],["13\/10\/2013",0,1,204,11]]);
Now the chart renders (as expected, because the returned data from my php script is correct):
This is a bit bizarre; does any one know why the chart doesn't work when it's loaded from the variable?
I have a php script that generates the google chart data and returns it in json encoded format. It's loaded into google chart using jQuery $.get() method. When I pass the return data to the google "arrayToDataTable" function like this:
var googleChartData = google.visualization.arrayToDataTable(chartData);
I get this error:
So, what I did was I dumped the value of my variable "chartData" and I got the following:
So, what I did was, copy this data from console window into the "arrayToDataTable" function manually like this:
var googleChartData = google.visualization.arrayToDataTable([["Date Range","0001\/102\/0 Available","0001\/102\/0 Unavailable","0001\/102\/1 Available","0001\/102\/1 Unavailable"],["02\/10\/2013",0,1,110,11],["03\/10\/2013",0,1,189,11],["04\/10\/2013",0,1,189,11],["06\/10\/2013",0,1,189,10],["07\/10\/2013",0,1,187,10],["08\/10\/2013",186,11,0,1],["09\/10\/2013",186,11,0,1],["10\/10\/2013",0,1,186,11],["11\/10\/2013",0,1,204,11],["13\/10\/2013",0,1,204,11]]);
Now the chart renders (as expected, because the returned data from my php script is correct):
This is a bit bizarre; does any one know why the chart doesn't work when it's loaded from the variable?
Share Improve this question edited Oct 16, 2013 at 10:31 Wooble 90k12 gold badges110 silver badges132 bronze badges asked Oct 16, 2013 at 10:04 LatheesanLatheesan 24.1k34 gold badges110 silver badges212 bronze badges 1- For pleteness, here's my javascript function pastebin./A6YFy44J and here's my cut down / dummy php script (that provides the data for chart) pastebin./LqH8C95v – Latheesan Commented Oct 16, 2013 at 10:09
1 Answer
Reset to default 12I've solved it by changing arrayToDataTable line like this:
var googleChartData = google.visualization.arrayToDataTable($.parseJSON(chartData));
Thanks to this post: https://stackoverflow./a/9420583/2332336