Brian Tran
Brian Tran

Reputation: 37

Manually set y-axis min and max value and zoom-in behaviour in Highcharts

I want to know the rounded min and max value that Highcharts will set on each axis before those are rendered out given minValue, maxValue and tickAmount.

My current solution is to manually calculate tickPositions so that it will show exactly what I set. So in a way, I know the values of them beforehand. The problem with this is when I zoom in, no new ticks for the zoomed-in interface are added. The reason for this is because the tickPositions attribute has blocked it from adding new ticks.

I have two questions:

Upvotes: 0

Views: 412

Answers (1)

ppotaczek
ppotaczek

Reputation: 39139

You can use tickPositioner function to define your own logic to draw ticks:

yAxis: {
    tickPositioner: function(min, max) {
        if (this.chart.resetZoomButton) { // zoomed chart
            return [1, 7]
        }

        return [1, 3, 5, 7]
    }
}

Live demo: http://jsfiddle.net/BlackLabel/s8Ldhfcy/

API Reference: https://api.highcharts.com/highcharts/yAxis.tickPositioner

Upvotes: 1

Related Questions