Highcharts - TickInterval with datetime values

无人久伴 提交于 2020-07-22 05:25:32

问题


From the highcharts docs : http://api.highcharts.com/highstock#xAxis.tickAmount

I can see tickInterval is not avilible for datetime axis, So my question is, is there a workaround to set the number of ticks labels in my xAxis?

I tried to play with it for a while, till now no success.


回答1:


This answer is assuming you indeed want tickInterval and not tickAmount.

I've successfully used tickInterval for datetime axes. It all depends on how much time you want between each tick mark.

For example, if you want to display a tick for each calendar year, you could do the following:

tickInterval: 1000 * 60 * 60 * 24 * 365
// milliseconds * seconds * minutes * hours * days = 1 year

I hope this is helpful!




回答2:


the value like this.dataMin / this.dataMax is seconds,not milliseconds

tickPositioner: function(){
    var positions = [] ;
    var min = Math.floor(this.dataMin) ;
    var max = Math.floor(this.dataMax) ;
    var gap = (max - min) / (60*60*24*30) ;
    var d = new Date(this.min*1000);

    for(i=0;i < (gap+1);i++){
        var d2 = new Date( d.getFullYear()+'-'+(d.getMonth()+1+i)+'-01');
        positions.push(d2.getTime()/1000);
    }
    return positions;
}


来源:https://stackoverflow.com/questions/38076540/highcharts-tickinterval-with-datetime-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!