Highcharts - 为数组中的标志传递数据。它没有渲染

时间:2012-08-29 01:30:53

标签: arrays highcharts flags

我试图在Highchart的烛台图表中渲染3个标志(试验旗帜),但是标志{x:Date.UTC(2012,7,6),标题:'On series'} 没有得到渲染。为什么呢?

$(function() {
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function(data) {

        // split the data set into ohlc and volume
        var ohlc = [],
            volume = [],
            dataLength = data.length,
            arrflag =[
            {x: Date.UTC(2012, 7, 17),title: 'On series'},
            {x: Date.UTC(2012, 7, 9),title: 'On series'}
            ];

        arrflag.push([
           {x: Date.UTC(2012, 7, 6),title: 'On series'}
        ]);

        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]
        ]];

        // create the chart
        chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container',
                alignTicks: false
            },

            rangeSelector: {
                selected: 0
            },

            title: {
                text: 'AAPL Historical'
            },

            yAxis: [{
                title: {
                    text: 'OHLC'
                },
                height: 200,
                lineWidth: 2
            }, {
                title: {
                    text: 'Volume'
                },
                top: 300,
                height: 100,
                offset: 0,
                lineWidth: 2
            }],

            series: [{
                type: 'candlestick',
                name: 'AAPL',
                id: 'AAPLX',
                data: ohlc,
                dataGrouping: {
                    units: groupingUnits
                }
            }, {
                type: 'column',
                name: 'Volume',
                data: volume,
                yAxis: 1,
                dataGrouping: {
                    units: groupingUnits
                }
            },{
                type: 'flags',
                name: 'Flags on series',
                data: arrflag,
                onSeries: 'AAPLX',
                shape: 'squarepin'
            }]
        });
    });
});​

Live DEMO

1 个答案:

答案 0 :(得分:0)

array个标志具有以下值:

arrflag =[
    {x: Date.UTC(2012, 7, 17),title: 'On series'},
    {x: Date.UTC(2012, 7, 9),title: 'On series'}
];

当你推送另一个flag时,你将它添加到另一个数组,这不是预期的。结果将是。

arrflag =[
    {x: Date.UTC(2012, 7, 17),title: 'On series'},
    {x: Date.UTC(2012, 7, 9),title: 'On series'},
    [{x: Date.UTC(2012, 7, 6),title: 'On series'}]
]; 

从以下代码中删除[]

arrflag.push([
    {x: Date.UTC(2012, 7, 6),title: 'On series'}
]);