4
votes

In my highchart, at some point, I need to update min, max and tickInterval of a yAxis. I tried 3 ways:

  1. I tried the following code, but it says "object# has no menthod 'update'"

    var extremes = chart.yAxis[i].getExtremes();
    chart.yAxis[i].update({
            min: extremes.dataMin * 1.1,
            max: extremes.dataMax * 1.1,
            tickInterval : SomeValue,
        });
    
  2. Also I tried chart.redraw as well... using the following code

     chart.yAxis[i].min = extremes.dataMin * 1.1;
     chart.yAxis[i].max = extremes.dataMax * 1.1;
     chart.yAxis[i].tickInterval = SomeValue;
     chart.redraw();
    

    This time it does not show any error, but the chart does not refreshed as well.

  3. This time,I tried to update the options and then to create a new highchart:

    options.yAxis[i].min = extremes.dataMin * 1.1;
    options.yAxis[i].max = extremes.dataMax * 1.1;
    options.yAxis[i].tickInterval = SomeValue;
    chart = new Highcharts.Chart(options);
    

It works this time, but I dont want to create a new highchart, I want to update the old one, because I am using it in one another method too.

Please let me know, how this can work, and also if I create new highchart using the 3rd way, then is there a way to get the latest 'chart' variable in another method?

Thank you

4
First method should work. Make sure you have latest, 3.0 Highcharts version. - Paweł Fus

4 Answers

7
votes

See this highcharts API:

setExtremes (Number min, Number max, [Boolean redraw], [Mixed animation])

Link: http://api.highcharts.com/highcharts#Axis.setExtremes()

They also have some jsfiddle examples there.

EDIT: to change the tickinterval try following:

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

Add this too after the above line:

chart.xAxis[0].isDirty = true;
0
votes

you should use other object to trigger yAxis's update method.

exp:

var chart = new Highcharts(config);

var axes = chart.axes; // this is all Axis object
var xAxis = axes[0]; // by array's method get axis object
var yAxis = axes[1];

// now, object is ok, next trigger update method
yAxis.update(<your attribute config>);

highcharts versions by: "4.1.9"

-1
votes

You have only one option:

$(container).highcharts({
    xAxis: {
        max: 10 //you can set the maximum here
    }
})

The maximum value can be defined only once. After that, any other changes have no effect to the chart.

chart.xAxis[0].options.max = 12; //this statement has no effect
-1
votes

Add below lines before setting chart.addSeries

chart.options.series = false;
chart = new Highcharts.Chart(chart.options);
chart.render();