Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force highcharts to show every x-axis label regardless of spacing constraints?

Tags:

highcharts

I'd like to show every x-axis label, and you can see it's only showing every other one:

http://jsfiddle.net/f48cjf01/2/

The relevant code:

xAxis: {
    categories: _.pluck(_mainData, "number")
    , labels: {
         rotation: 290
         , step: 1 //show every tick regardless of spacing
         , align: 'right'
    }
}

What do I need to do to show every tick? (I know it may look ugly here considering how little space there is...but I'd like to force it nonetheless)

like image 382
TimDog Avatar asked Jan 09 '23 10:01

TimDog


1 Answers

One solution is to use a tickPositioner function and specify every single index:

xAxis: {
    tickPositioner: function() {
        var result = [];
        for(i = 0; i < _mainData.length; i++)
            result.push(i);
        return result;
    }
}

See this JSFiddle example. You can remove xAxis.labels.step when using this.

At first tickInterval looks easier, but unfortunately doesn't work because of the following note:

If the tickInterval is too dense for labels to be drawn, Highcharts may remove ticks.

like image 157
Halvor Holsten Strand Avatar answered Feb 18 '23 11:02

Halvor Holsten Strand