push max values past preset in line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

push max values past preset in line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
$(function () {//from   w ww . j  a va2  s.c o  m
    Array.prototype.max = function() {
      return Math.max.apply(null, this);
    };
    var data1 = [600, 621, 628, 656, 612, 676, 641, 648, 708, 665, 659, 640],
        data2 = [672, 689, 4820, 4864, 4871, 4880, 4869, 7786, 7692, 7744, 4770, 5769],
        max = data2.max();
        $('#container').highcharts({
            title: {
                text: 'Monthly Average Temperature',
                x: -20 //center
            },
            subtitle: {
                text: 'Source: WorldClimate.com',
                x: -20
            },
            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            },
            yAxis: {
            min: 0,
                max: max > 7000 ? max : 7000,
            tickInterval: 1000,
                title: {
                    text: ''
                },
            },
            tooltip: {
                valueSuffix: '?C'
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: [{
                name: 'Elec',
                type: 'spline',
                shadow : true,
                color: {
                    linearGradient: [0, 200, 0, 0],
                    stops: [
                        [0, '#19c7e6'], // Blue
                        [0.1, '#0b74d1'], // D-Blue
                        [0.3, '#8a19c2'], // Purple
                        [0.6, '#c21919']  // red
                    ],
                },
                data: data1
            },{
                name: 'ElecOut',
                type: 'spline',
                shadow : true,
                color: {
                    linearGradient: [0, 200, 0, 0],
                    stops: [
                        [0, '#19c7e6'], // Blue
                        [0.1, '#0b74d1'], // D-Blue
                        [0.3, '#8a19c2'], // Purple
                        [0.6, '#c21919']  // red
                    ],
                },
                data: data2
            }]
        });
    });

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials