是否可以在窗格中使用TWO PANES和MULTIPLE SERIES创建Highstock图表

时间:2014-09-16 18:32:23

标签: javascript highcharts highstock

有人知道是否可以使用两个PANES创建一个图表,并且在一个窗格内,可以使用MULTIPLE SERIES吗?

我做了我需要的截图:

Example of TWO PANES chart with MULTIPLE SERIES in a pane

有没有人在JFiddler中有一个例子?

我已经尝试创建一个,但我没有成功......

此致

马塞洛

1 个答案:

答案 0 :(得分:1)

是的,我做到了!

Bellow按照我创建的源代码:

HTML

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

Javascript代码

$(function() {
    $.getJSON('http://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
                }
            }]
        });
    });
});

JSFiddler中的链接: http://jsfiddle.net/marcelojuventino/tc1a78ma/1/

感谢大家!