I have data like below:
store 1 Store 2
store_id walk-ins walk-ins
morning 20 25
noon 35 40
night 50 55
There are 20 stores to chart stacking the values of each row.
Google Charts docs tells me the data array looks like this:
var data = google.visualization.arrayToDataTable([
['Stores', 'Store 1', 'Store 2', 'Store 3', 'Store 4', ... ],
['morning', 10, 24, 20, 32, 18, 5, ...],
['noon', 16, 22, 23, 30, 16, 9, ...],
['night', 28, 19, 29, 30, 12, 13, ...],
]);
I am getting the data via MySQL script / server PHP script. What should the JSON look like? The json_encode($data)
from MySQL query returns as follows;
[{"store_name":"Store 1","Time":"Morning","count":"17"}, ...]
but the chart does not load and gives me a message "Table has no columns
".
I load JSON as follows:
var url = '/url/updatedata.php?var=querytype';
jQuery.getJSON( url, function(Json) {
// Create and populate the data table.
var data = new google.visualization.DataTable(Json);
....
What is the structure of the JSON for a stacked column chart?
Thanks!