Dale
Dale

Reputation: 2155

How do I dynamically change the yAxis min, max and tickInterval in HighCharts

I can set these values in the initial options object and everything works fine. If I later change the options using chart.options.yAxis.tickInterval for instance, they seem to get ignored when redrawing the yAxis.

    // Global variables
var markInterval = undefined;
var minInterval = 0;
var maxInterval = undefined;

chart = new Highcharts.Chart({
        // ... 
        yAxis: {
            title: {
                text: 'Mark'
            },
            labels: {
                formatter: function() {

                    // html formatting
                },
                useHTML: true
            },
            tickInterval: markInterval,
            min: minInterval,
            max: maxInterval
        },
        plotOptions: {
            series: {
                events: {
                    legendItemClick: function(event) {
                        // setTickIntervals(); Change the global values markInterval, minInterval and maxInterval
                        chart.options.yAxis.tickInterval = markInterval;
                        chart.options.yAxis.min = minInterval;
                        chart.options.yAxis.max = maxInterval;
                        chart.redraw();
                    }
                }
            }
        }
    });

Upvotes: 1

Views: 14332

Answers (1)

Dale
Dale

Reputation: 2155

I was incorrectly setting the new values, eg:

chart.options.yAxis.tickInterval = markInterval;

should be

chart.yAxis[0].options.tickInterval = markInterval;

then everything works as expected.

Upvotes: 12

Related Questions