Also I don't know how to do this without doing an eval() or other
jsonParse() first so I think you will need to add one line of code that puts
the json data into a variable. Kind of like this:
var data=eval($jsonstuff).pass_this_to_flot; // please don't flame me for
using eval() - it's for clarifcation only
Anyway the data you show below looks to me like invalid json. You need to
put braces {} around objects. So you need to add a brace around each
series. Something like this because flot expects an array of series
objects. My changes have "new!" after them
{ // note that you need to pass an array to flot, not an object, so I added
something inside this object called pass_this_to_flot which you should use
as the flot argument
"pass_this_to_flot":
[ // new! - begin the array to pass to flot
{// new! - first object in array is first series
"label":"MeasurementA",
"data":[
[1274337258000,70.0],
[1274337318000,71.0]
]// removed comma!
},{// new! second series
"label":"MeasurementB",
"data":[
[1274337009000,71.0],
[1274337579000,71.0]
]
}]// new!
}
- George Roberts
http://gr5.org
--------------------------------------------------
From: "Jake Lear" <jake...@gmail.com>
Sent: Monday, September 20, 2010 4:56 PM
To: "Flot graphs" <flot-...@googlegroups.com>
Subject: Multiple Series from JSON - Invalid JSON?
I'm not sure what was invalid about the json that you claim is invalid. I'm guessing it is because the word label wasn't in quotes? Is that it? Or something else?
I'm not sure what was invalid about the json that you claim is invalid. I'm guessing it is because the word label wasn't in quotes? Is that it? Or something else?
Basically what you did was unpack and repack the array back together. It is
fine unless you don't know how many elements are in the array.
You can simplify the code further by getting rid of 'output' altogether:
> $.plot($("#chart-container"), data.measurements, { xaxis: { mode:
Also a side note - flot has no knowledge of double quotes versus single
quotes versus no quotes for the labels as by the time flot sees these
objects they are already, well, objects. jquery probably cares because I
suspect it doesn't use eval(). If it *does* use eval then it would be based
on the browser. For a browser to get picky about that syntax would break so
much existing javascript code that it would be a disaster so I'm not too
worried about it.