Here is my question
when i run the below code which is php with codeigniter framework
$data= $datatable->result();
foreach ($data as $graph) {
$to_graph[] = "Date.UTC(".$graph->year.")," . $graph->ANN ;
}
return json_encode($to_graph);
i get the following out put
["Date.UTC(2040),934","Date.UTC(2040),1003","Date.UTC(2040),1747","Date.UTC(2040),1336","Date.UTC(2040),973","Date.UTC(2040),912","Date.UTC(2040),1112","Date.UTC(2040),793","Date.UTC(2040),973","Date.UTC(2040),786","Date.UTC(2040),759","Date.UTC(2040),1001","Date.UTC(2040),1221","Date.UTC(2040),1270","Date.UTC(2040),1355","Date.UTC(2040),923","Date.UTC(2040),942","Date.UTC(2040),999","Date.UTC(2040),1128","Date.UTC(2040),908"]
But for highcharts highstock to draw it on the graph it needs to be displayed like this
[Date.UTC(2003),0.8709],
[Date.UTC(2003),0.872],
[Date.UTC(2003,26),0.8714],
[Date.UTC(2003),0.8638],
[Date.UTC(2003),0.8567],
[Date.UTC(2005),0.8536],
[Date.UTC(2005),0.8564],
[Date.UTC(2005),0.8639],
[Date.UTC(2009),0.8538],
[Date.UTC(2009),0.8489],
[Date.UTC(2009),0.8459],
[Date.UTC(20011),0.8521],
[Date.UTC(2011),0.6945]
]);
so can you help me in converting my json out put to that of highstocks without the quotes ""
Thanks
$json = json_encode($to_graph);
As easy as that. Make sure your data is UTF-8 encoded first. Also you need the quotes, as that's how json interprets a string.
Converting to JSON is not your problem. That is a trivial one-line last step in PHP. You just need to think about how to make your data into a multi-dimensional array as is expected in the input format. I honestly don't see the correlation in the sample data you provided to understand exactly how you need to get your data into the desired format (that data you show doesn't seem to match).
I would guess however that the approach would be something like:
$data= $datatable->result();
foreach ($data as $graph) {
$to_graph[] = array("Date.UTC(" . $graph->year . ")", $graph->ANN);
}
$json = json_encode($to_graph);
Generally in the JSON you cannot use functions, so Date.UTC() doens't make sense. I advice to remove Date.UTC, and prepare timestamp in PHP. Then in json_encode() use flag JSON_NUMERIC_CHECK. As a result you receive json, which will not to be parsed in javascirpt, only used.