jqPlot DateAxis tickInterval not working

前端 未结 5 611
无人及你
无人及你 2020-12-01 18:47

I\'m trying to draw a chart with a single datapoint each month. I\'m sending this through to jqPlot as a single point on the first of each month:

$.jqplot(\'         


        
相关标签:
5条回答
  • 2020-12-01 19:36

    Since I think you cannot answer your own question (and I ran in to the same problem), i'll post your solution as answer, as it solved it on my side too:

    Providing a min attribute for the axis does appear to fix this (for whatever reason... bug?), so unless anyone has any better ideas I'll do this!

    0 讨论(0)
  • 2020-12-01 19:38

    You should specify a timestamp on your plot data. As noted on jqplot example of Date Axes:

    Note, although jqPlot will parse most any human readable date, it is safest to use javascript time stamps when possible. Also, it is best to specify a date and time and not just a date alone. This is due to inconsistent browser handling of local time vs. UTC with bare dates.

    You can check it here: http://www.jqplot.com/deploy/dist/examples/date-axes.html

    I'm mentioning it because i've stumbled upon this problem 2 days ago. I solved it by passing a timestamp and defining a greater tickInterval than '1 day'.

    0 讨论(0)
  • 2020-12-01 19:39

    I found a solution! You need to specify the tickinterval as a javascript timestamp. So lets say you want 1 hour. That would be 1000*60*60 = 3600000 (javascript timestamps are in milliseconds).

    So you would write: tickInterval:'3600000',

    Works here.

    0 讨论(0)
  • 2020-12-01 19:39

    I looked into the jqplot.dateAxisRenderer.js, and it looks like the reset function needs to be called in order for the this.tickInterval variable to get set. I vaguely recall that you can manually reset the renderer, but do note that tick interval is specified in the millisecond format (at least, I didn't catch any translation with my quick glance).

    I think this is just a bug.

    And on a side note, I commented out the only min.getUtcOffset() call in the function, since it was introducing unwanted "drift" (I want local time), and causes the graph to get chopped off on the left.

    0 讨论(0)
  • 2020-12-01 19:44

    tickInterval:'1 day' works. You can try:

    xaxis: {
            renderer: $.jqplot.DateAxisRenderer,
            rendererOptions: { tickRenderer: $.jqplot.CanvasAxisTickRenderer },
            tickOptions: { formatString: '%b' },
            tickInterval: '1 day'
           }
    
    0 讨论(0)
提交回复
热议问题