Reputation: 76
I'm struggled with jQuery Flot chart, the chart is being populated fine with this data:
{"facebook_users":[["25",0],["26",0],["27",0],["28",0],["29",0],["30",0],["31",0],["01",0],["02",0],["03",0]],"email_users":[["25",0],["26",0],["27",0],["28",1],["29",1],["30",3],["31",1],["01",0],["02",0],["03",0]],"max":10}
Producing this chart:
As you may noticed, this is a chart that shows the users registered by email/address in a day by day basis. The problem is that it appears to reorder the JSON data ascending, starting from 1 to XX. As this data is 7-days long, can be month-cross, provoking the error.
I've readed carefully the project documentation, but can't find a solution. The chart should show the data as the JSON, without reordering.
Upvotes: 2
Views: 1066
Reputation: 38189
Flot isn't re-ordering the data; it's just that the values are [x, y] pairs, and an X value of 1 is plotted at the same position on the x-axis regardless of where it appears in the sequence.
There are several ways to solve this:
Use the time plugin, provide the values as timestamps instead of days, then use a formatter of '%d' to extract just the day portion.
Provide your own tick generator function to produce them in the order you want, i.e. 30, 31, 1, ...
Use the categories plugin to interpret the values as strings rather than numbers.
Upvotes: 2