Search code examples
javascriptjquerygraphchartsflot

keep right position label x-axis jquery flot


I'm finding about jquery flot.

So, i had a problem, that i want to hard fix grid value on x-axis.

For examples:

It will update realtime.

[4:02, 5:02, 6:02, 7:02, 8:02, 9:02] after 1 hour, it only change label value and keep right position.

4:02 become 5:02 and keep right position, 5:02 become 6:02 and keep right position,...

enter image description here

Hope every body can support me, thank you very much.

Here is my demo: my demo


Solution

  • Instead of only adding new ticks after each hour you have to generate the complete tick array after every update with something like this (updated fiddle):

    var first_hour = data_speed_hour[0][0];
    options_hour.xaxis.ticks = [
        first_hour,
        first_hour + 3600000*1,
        first_hour + 3600000*2,
        first_hour + 3600000*3,
        first_hour + 3600000*4,
        first_hour + 3600000*5,
        first_hour + 3600000*6 //- 600000
      ];