0

我有来自服务的 ohlc 数据,时间每分钟都在变化,我正在使用 highstocks 来绘制分钟烛台,但它只显示最后一根蜡烛,而之前的蜡烛正在消失。如果我使用当前时间(以毫秒为单位)作为 ohlc 的属性,它可以工作,但我想使用来自服务器的分钟时间

    this.options = {
        chart: {
            width: 1200 ,
            height:800,
            type: 'candlestick'
        },

        title: { text : 'dynamic data example'},
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats : {
                hour: '%I %p',
                minute: '%I:%M %p'
            }
        },
        yAxis: {
            title: {
                text: 'Value'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        rangeSelector: {
            selected: 1
        },
        dataGrouping: {
            units: [
                ['minute', [1]], [
                'hour', [1, 2, 3, 4, 6]]
            ]
        },
        series: [{
            name: 'Random data',
            type: 'candlestick',
            data: (function() {
                // generate an array of random data
                var data:any = [],
                    time = (new Date()).getTime(),
                    i:any;

                for (i = -5; i <= 0; i++) {
                    data.push([
                        time + i * 60000,
                        Math.random()*100,
                        Math.random()*100,
                        Math.random()*100,
                        Math.random()*100
                    ]);
                }
                return data;
            })()}

            ]
    };
    this.connection = this.socketService.getMessages().subscribe(data => {
        this.data = data;

         this.chart.series[0].addPoint([
             this.data.time,
             this.data.open,
             this.data.high,
             this.data.low,
             this.data.close,
         ], true, true);

    })
4

1 回答 1

0

删除 true 选项解决了该问题。

this.chart.series[0].addPoint([this.data.time, this.data.open, this.data.high, this.data.low, this.data.close,], true, true);

于 2017-03-14T20:37:47.433 回答