1
votes

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.

2
You're linking tickAmount, tickInterval does work on datetime axes.apokryfos
but i dont want tickInterval... i want tickAmount... i am trying to find a workaround to get his functionality, i found some solution but not optimalomriman12
Easiest way to work around this is get the time difference between earliest/latest in milliseconds and then divide it by the tickAmount and use that as your tickInterval. But do update your question with what you really need, it's still saying that you need tickInterval.apokryfos
The tickInterval works well, morever you can use i.e tickPositioner and apply as much ticks as you need. Example: jsfiddle.net/3p2bfseuSebastian Bochan

2 Answers

6
votes

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!

0
votes

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