I have a Flot chart and x-axis displays time - tick size equaling one day. I am displaying durations of events that take place at various times of the day and I would like to stack them. Flot's time mode po开发者_如何学运维sitions the bars based on milliseconds so the bars are apart in each tick/day. Is there a quick way of making the bars stack up, preventing them from being plotted in different x positions in each day?
Having mixed feelings answering my own question, but I'll do it anyway in case someone runs into a similar issue.
The solution is to convert timestamps to days, round down the decimal in the result, and convert it back to milliseconds using a function like:
Math.floor(date/(1000*60*60*24))*(1000*60*60*24)
Also, make sure to set the tick size to one day in your axis settings declaration:
tickSize: [1, "day"]
As a result, you will end up with day values that stack up beautifully. I ended up doing the conversion on the client side so that I can store precise values, while the graph shows a bigger picture.
精彩评论