create a chart using TWO PANES and MULTIPLE SERIES in a pane - Javascript highcharts

Javascript examples for highcharts:Chart Series

Description

create a chart using TWO PANES and MULTIPLE SERIES in a pane

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  w  w . ja va2s  .c  o m
    $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function(data) {
        var ohlc = [],
            ohlc2 = [],
            volume = [],
            dataLength = data.length,
            groupingUnits = [
                ['week', [1]],
                ['month', [1, 2, 3, 4, 6]]
            ],
            i = 0;
        for (i; i < dataLength; i += 1) {
            ohlc.push([
                data[i][0], // the date
                data[i][1], // open
                data[i][2], // high
                data[i][3], // low
                data[i][4]  // close
            ]);
            ohlc2.push([
                data[i][0],       // the date
                data[i][1] - (Math.ceil(Math.random()*100)+100), // open
                data[i][2] - (Math.ceil(Math.random()*100)+100), // high
                data[i][3] - (Math.ceil(Math.random()*100)+100), // low
                data[i][4] - (Math.ceil(Math.random()*100)+100)  // close
            ]);
            volume.push([
                data[i][0], // the date
                data[i][5]  // the volume
            ]);
        }
        // create the chart
        $('#container').highcharts('StockChart', {
            rangeSelector: {
                inputEnabled: $('#container').width() > 480,
                selected: 1
            },
            title: {
                text: 'Two Panes & Multiple Series'
            },
            yAxis: [{
                labels: {
                    align: 'right',
                    x: -3
                },
                title: {
                    text: 'OHLC'
                },
                height: '60%',
                lineWidth: 2
            }, {
                labels: {
                    align: 'right',
                    x: -3
                },
                title: {
                    text: 'Volume'
                },
                top: '65%',
                height: '35%',
                offset: 0,
                lineWidth: 2
            }],
            series: [{
                name: 'AAPL',
                data: ohlc,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                name: 'AAPL2',
                data: ohlc2,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                name: 'Volume',
                data: volume,
                yAxis: 1,
                dataGrouping: {
                    units: groupingUnits
                }
            }]
        });
    });
});

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

Related Tutorials