0

我正在尝试在 Highchart 的烛台图表中渲染 3 个标志(用标志进行实验),但标志 {x: Date.UTC(2012, 7, 6),title: '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'
            }]
        });
    });
});​

现场演示

4

1 回答 1

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'}
]);
于 2012-08-29T01:59:27.317 回答