Search code examples
javascriptjqueryplotchartsflot

x-axis display uncorrect time after a mount of time using flot


I had a problem with jquery flot. I'm going to make a realtime chart. It worked as well, but after sometimes, i realized a big problem.

At the first time, everything worked as well, but after 10 minutes, the time on x-axis seems later than time on computer.

And i didn't understand why ?

This is my demo: demo


Solution

  • You use setTimeout(update, 1000); to update your graph every second and increment the x axis tick by one second. But the updating itself also takes a few milliseconds. After a few minutes this leads to a visible shift in time on the x axis.

    Solution: Use the actual time to generate the tick, not some calculated value (your now_hour variable).