omriman12
omriman12

Reputation: 1690

Highcharts - TickInterval with datetime values

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.

Upvotes: 1

Views: 9889

Answers (2)

foolray
foolray

Reputation: 1

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;
}

Upvotes: 0

Mike Zavarello
Mike Zavarello

Reputation: 3554

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!

Upvotes: 9

Related Questions