get max value by comparing dual y-axis in line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

get max value by comparing dual y-axis in line chart

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 {//  w  w w .  j av  a  2  s . c  o m
   min-width: 310px;
   max-width: 800px;
   height: 400px;
   margin: 0 auto
}


      </style> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container"></div> 
      <script type="text/javascript">
Highcharts.chart('container', {
    chart: {
        events: {
            load: function() {
                var series = this.series,
                    max = series[0].dataMax,
                    min = series[0].dataMin;
                series.forEach(function(serie) {
                    if (serie.dataMax > max) {
                        max = serie.dataMax;
                    }
                    if (serie.dataMin < min) {
                        min = serie.dataMin;
                    }
                });
                this.yAxis[0].update({
                    min: min,
                    max: max
                });
            }
        }
    },
    series: [{
        data: [1, 21, 42, 11, 42, 12],
        yAxis: 1
    }, {
        data: [111, 231, 161, 151],
        yAxis: 0
    }],
    yAxis: [{
    }, {
        linkedTo: 0,
        opposite: true
    }]
});

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

Related Tutorials