flot gets the data from json but shows blank graph
This is the code, when i mannually paste the json data inplace of series the graph is obtained but through ajax call am able to get the json data but the chart is blank.
$(document).ready(function(){
$.ajax({
url:"sqljson.php",
method:"GET",
datatype:"json",
success:graph
})
function graph(series){
var data=series;
alert(series);
var options={
lines:{show:true},
points:{show:true,hoverable:true},
grid:{hoverable:true,clickable:true}
}
$.plot($("#place"),[data], options);
}
});开发者_Go百科
json data:obtained on the alert window
[["253","5"],["254","32"],["255","10"],["256","50"],["257","1"],["258","2"["259","100"],["260","38"],["261","2"],["262","20"],["263","2000"],["264","500"], ["265","400"],["266","10"],["267","50"],["268","9"],["269","200"],["270","40"]["271","700"],["272","188"],["273","73"]]
As per the Flot FAQ:
Q: Flot isn't working when I'm using JSON data as source!
A: Actually, Flot loves JSON data, you just got the format wrong. Double check that you're not inputting strings instead of numbers, like [["0", "-2.13"], ["5", "4.3"]]. This is most common mistake, and the error might not show up immediately because Javascript can do some conversion automatically.
You need to change your output JSON so there are no quotes, i.e.:
[[253,5],[254,32],[255,10],[256,50],[257,1],[258,2],[259,100],[260,38],[261,2],[262,20],[263,2000],[264,500],[265,400],[266,10],[267,50],[268,9],[269,200],[270,40][271,700],[272,188],[273,73]]
However, this may not do it, it needs to be in a format similar to this, so:
{
"label": "example",
"data": [[253,5],[254,32],[255,10],[256,50],[257,1],[258,2],[259,100],[260,38],[261,2],[262,20],[263,2000],[264,500],[265,400],[266,10],[267,50],[268,9],[269,200],[270,40][271,700],[272,188],[273,73]]
}
精彩评论