score:5

Accepted answer

it seems that there is no maxrange equivalent (feature request, torstein?) so that the axis maximum has to be determined before highcharts is called. building upon sanath's suggestion a solution would be this:

$(function () {
   var seta = [29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4];
   var setb = [129.2, 144.0, 176.0, 135.6, 248.5, 316.4, 694.1, 795.6, 954.4, 1029.9, 1171.5, 1506.4];
   var data = math.random() < 0.5 ? seta : setb;
   var height=math.max.apply(math, data);
   if(height > 1000){ height = 1000; }

   $('#container').highcharts({
       chart: {
           marginright: 80 // like left
       },
       xaxis: {
           categories: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
       },
       yaxis: [{
           linewidth: 1,
           max: height,
           min: 0,
           title: { text: 'yaxis' }
       }],
       series: [{
           data: data
       }]
   });
});

as working example: http://jsfiddle.net/panicj/h2pyc/8/

score:1

updated jsfiddle

$(function() {
    $('#container').highcharts({
        chart: {
            marginright: 80 // like left
        },
        xaxis: {
            categories: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
        },
        yaxis: [{
            linewidth: 1,
            max: 1000,
            min: 0,
            title: {
                text: 'primary axis'
            }
        }, {
            linewidth: 1,
            opposite: true,
            title: {
                text: 'secondary axis'
            }
        }],
        series: [{
            data: [29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4]
        }]
    });
    $('#button').click(function() {
        var chart = $('#container').highcharts();
        if ($(this).hasclass('big')) {
            $(this).removeclass('big');
            chart.series[0].setdata([29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4]);
            chart.yaxis[0].setextremes(0, 50);
        } else {
            $(this).addclass('big');
            chart.series[0].setdata([129.2, 144.0, 176.0, 135.6, 248.5, 316.4, 694.1, 795.6, 954.4, 1029.9, 1171.5, 1506.4]);
            chart.yaxis[0].setextremes(0, 1600);
        }
    });
});

this solution should work for you, you just need to set yaxis extremes for the chart, if you know the maximum data range for each series it would be easy, otherwise you need to calculate the maximum value for each series.

score:1

since highcharts 4.0 we can use yaxis.ceiling and yaxis.floor, demo.

highcharts.chart('container1', {
  yaxis: {
    floor: 0,
    ceiling: 100
  },
  series: [{
    data: [-10, 1, 0, 2, 3, 5, 8, 5, 15, 14, 25, 154]
  }]
});

score:4

please use setextremes to define a range. the jsfiddle has been updated.

 $('#button').click(function () {
    var chart = $('#container').highcharts(

    );
    if ($(this).hasclass('big')) {
        $(this).removeclass('big');
        chart.series[0].setdata([29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4]);
        //chart.setsize(null,100,true);
        chart.yaxis[0].setextremes(0,50);
    } else {
        $(this).addclass('big');
        chart.series[0].setdata([129.2, 144.0, 176.0, 135.6, 248.5, 316.4, 694.1, 795.6, 954.4, 1029.9, 1171.5, 1506.4]);
        //chart.setsize(null,1600,true);
        chart.yaxis[0].setextremes(0,1600);
    }
    });
});

Related Query

More Query from same tag