I have the following code:
<?php
//mysqli query here
$table = array();
$table['cols'] = array(
array('id' => '', 'label' => 'Date', 'type' => 'date'),
array('id' => '', 'label' => 'Amount ', 'type' => 'number'),
);
$rows = array();
foreach($result as $row){
$temp = array();
$date1 = date_create_from_format('Y-m-d H:i:s', $row['Date']);
$date2 = date_format($date1, 'm-d-Y');
$temp[] = array('v' => (string)'new Date("'.$date2.'")');
$temp[] = array('v' => (float) $row['Amount']);
$rows[] = array('c' => $temp);
}
$result->free();
$table['rows'] = $rows;
$jsonTable = json_encode($table, true);
echo $jsonTable;
?>
This outputs the following data to a google line chart:
{"cols":[
{"label":"Reading Date","type":"date"},
{"label":"Reading ","type":"number"},
"rows":[
{"c":[{"v":"new Date(10\/04\/2015)"},{"v":0.4}]},
{"c":[{"v":"new Date(02\/18\/2016)"},{"v":0.6}]}]}
However i need it to be in the exact following format for the chart to work properly:
{"cols":[
{"label":"Reading Date","type":"date"},
{"label":"Cl Reading(mg\/l) ","type":"number"}
],
"rows":[
{"c":[{"v":new Date("10/04/2015")},{"v":0.4}]},
{"c":[{"v":new Date("02/18/2016")},{"v":0.6}]}
]}
so really im looking at just one line that needs changing but cant seem to get it into the format i need:
$temp[] = array('v' => (string)'new Date("'.$date2.'")');
Can anyone help me on this? I know its probably simple but just cant seem to get it..