I have some PHP code that outputs a JSON array when $.getJSON is called:
.
.
.
$data = array_combine($date_dispatched,$amount);
echo json_encode($data);
This is collected by:
$.getJSON('statistics_get.php',function(output) {
$.plot($("#graph_1"), [{
data: output,
lines: {show:true}
}]
);
});
Now, using firebug, the response I get back is of the form:
{"0":"0","1296658458000":"566","1296725534000":"789","1297072385000":"890","1297072388000":"435"}
Flot is not processing this data. I believe Flot needs it to be in the form [[1,2],[4,5],[6,9]] etc. So my question is, what is the best way of getting this JSON array into the correct form for flot to read and produce a graph.
Don’t use
array_combine, since it doesn’t do what you need. Doing “zip” in PHP is a little bit unpleasant, but you should be able to manage with:And then JSON-encode that.