Combine both bar chart and line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

Combine both bar chart and line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>ElementStacks</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.js"></script> 
      <script type="text/javascript" src="http://highcharts.com/js/testing.js"></script> 
      <script type="text/javascript">
    $(function(){/*from   w w  w  .j av  a  2 s.co  m*/
function newRandomData(n) {
    // generate an array of random data
    var data = [],
        time = (new Date()).getTime(),
        i;
    for (i = -1 * n; i <= 0; i++) {
        data.push(Math.random() * 200 - 100);
    }
    return data;
}
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
    },
    yAxis: [{
        opposite: false
    }, {
        opposite: true
    }],
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },
    series: [{
        type: 'spline',
        showInLegend: false,
        color: 'red',
        name: 'first',
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }, {
        type: 'column',
        name: 'third',
        color: 'rgba(0,245,0,0.6)',
        data: newRandomData(11),
        yAxis: 1,
        marker: {
            enabled: false
        }
    }]
});
$('#b0').click(function () {
    var i = 15;
    while (chart.yAxis[1].translate(0) != chart.yAxis[0].translate(0) && i > 0) {
        chart.yAxis[0].setExtremes(chart.yAxis[0].getExtremes().min - chart.yAxis[0].translate(chart.yAxis[1].translate(0), true));
        i--;
    };
});
    });

      </script> 
   </head> 
   <body> 
      <div id="container" style="height: 300px"></div> 
      <script src="https://code.highcharts.com/highcharts.src.js"></script> 
      <button id="b0">Make simililar zeros</button>  
   </body>
</html>

Related Tutorials