I'm using flot (flot on github) to draw a graph with the following time series data:
[
[1357171200000, 1],
[1357344000000, 1],
[1357430400000, 2],
[1357516800000, 2],
[1357689600000, 3],
[1357776000000, 1]
]
As you can see there are some points in the graph wich show the sales for the given day. My json response doesn't contain sales count / data for days where no sale has happened. For example the 04th of January. How can i configure flot to draw the missing days on y-axis at point zero (because there are no sales)? As you can see in the image flot does connect the points so there are no zero points in the graph.
So, you have daily count. You can then iterate over each entry and find the number of day between the current entry and the next one, then you will just need to fill you array with 0.
It is much better to use an zero filled array and then add only the count for the date you have in your current array, then you will not need to do any check on the date.
You daily interval
This will give you the number of daily interval
Then when you iterate over your array of date
Check in which interval is the date, and update the count in the 'interval' array (
counts
)And then you can play with
index
to map the count with a particular day:Here's a solution that creates a new Array adding in missing days and setting their values to zero:
To use:
DEMO: http://jsfiddle.net/LK2gD/3/