php - Make JSON array Flot compatible -
i have php code outputs json array when $.getjson called:
. . . $data = array_combine($date_dispatched,$amount); echo json_encode($data);
this collected by:
$.getjson('statistics_get.php',function(output) { $.plot($("#graph_1"), [{ data: output, lines: {show:true} }] ); });
now, using firebug, response of form:
{"0":"0","1296658458000":"566","1296725534000":"789","1297072385000":"890","1297072388000":"435"}
flot not processing data. believe flot needs in form [[1,2],[4,5],[6,9]] etc. question is, best way of getting json array correct form flot read , produce graph.
don't use array_combine
, since doesn't need. doing "zip" in php little bit unpleasant, should able manage with:
function make_pair($date, $amount) { return array($date, $amount); } $data = array_map('make_pair', $date_dispatched, $amount);
and json-encode that.
Comments
Post a Comment