Highcharts使用烛台,音量和MACD

时间:2014-04-08 09:26:21

标签: php jquery json highcharts candlestick-chart

我是highcharts的新手,我正在使用hightcharts图,但音量没有显示。当我删除MACD然后音量显示我不明白为什么我得到这个问题!我的代码是

$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
    var ohlc = [],
        volume = [],
        dataLength = data.length;

    for (i = 0; i < dataLength; i++) {
        ohlc.push([
            data[i][0], // the date
            data[i][1], // open
            data[i][2], // high
            data[i][3], // low
            data[i][4] // close
        ]);

        volume.push([
            data[i][0], // the date
            data[i][5] // the volume
        ])
    }

    // set the allowed units for data grouping
    var groupingUnits = [[
        'week',                         // unit name
        [1]                             // allowed multiples
    ], [
        'month',
        [1, 2, 3, 4, 6]
    ]];
$(function() {
    $('#container').highcharts('StockChart', {

        title : {
            text : 'MACD of AAPL stock price'
        },

        subtitle: {
            text: 'From may 15, 2006 to May 10, 2013'
        },

        yAxis: [{
            title: {
                text: 'Price'
            },
            height: 200,
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        }, {
            title: {
                text: 'MACD'
            },
            top: 320,
            height: 100,
            offset: 0,
            lineWidth: 2
        }, {
            title: {
                text: 'Volume'
            },
            top: 500,
            height: 60,
            offset: 0,
            lineWidth: 2
        }],

        tooltip: {
            crosshairs: true,
            shared: true
        },

        rangeSelector : {
            selected : 1
        },

        legend: {
            enabled: true,
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },

        plotOptions: {
            series: {
                marker: {
                    enabled: false,
                }
            }
        },

        series : [{
           name: 'AAPL Stock Price',
            type : 'line',
            id: 'primary',
            data : data
        }, {
            name : 'MACD',
            linkedTo: 'primary',
            yAxis: 1,
            showInLegend: true,
            type: 'trendline',
            algorithm: 'MACD'

        }, {
            type: 'candlestick',
            name: 'AAPL',

            data: ohlc,
            dataGrouping: {
                units: groupingUnits
            }
        }, {
            type: 'column',
            name: 'Volume',
            linkedTo: 'primary',
            data: volume,
            yAxis: 1,
            dataGrouping: {
                units: groupingUnits
            }
        }, {
            name: 'Histogram',
            linkedTo: 'primary',
            yAxis: 1,
            showInLegend: true,
            type: 'histogram'

        }]
    });
});

});

output graph

为什么音量不显示? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

你有三个yAxis,但在每个系列中(除了第一个)你使用yAxis:1,这意味着系列显示在该轴上。所以你需要修改轴索引以显示在&#34; last&#34; Y轴。