set axis min/max after chart creation - Javascript highcharts

Javascript examples for highcharts:Chart Axis

Description

set axis min/max after chart creation

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

#container {/*from  ww w  . ja  va2 s .c  o m*/
   height: 300px;
   min-width: 310px;
   max-width: 800px;
}


      </style> 
   </head> 
   <body> 
      <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container"></div>
       Min: 
      <input id="min"> 
      <br>
       Max: 
      <input id="max"> 
      <button id="update">Update y-axis </button> 
      <script type="text/javascript">
var chart = Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Highcharts Demo'
    },
    subtitle: {
        text: 'Fill in y-axis values to change it'
    },
    legend: {
        align: 'right',
        verticalAlign: 'middle',
        layout: 'vertical'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Bananas'],
        labels: {
            x: -10
        }
    },
    yAxis: {
        allowDecimals: false,
        title: {
            text: 'Amount'
        },
        min: -5
    },
    series: [{
        name: 'x',
        data: [0, 4, 3]
    }, {
        name: 'y',
        data: [6, 4, 2]
    }, {
        name: 'z',
        data: [8, 4, 3]
    }],
});
$('#update').click(function () {
    chart.update({
       yAxis: {
           min: document.getElementById("min").value,
           max: document.getElementById("max").value,
           tickInterval: 5 //do calculations here to get needed tickInterval
       }
    })
});

      </script>  
   </body>
</html>

Related Tutorials