javascript 动态添加数据到 Highcharts 中的系列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24049421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:04:27  来源:igfitidea点击:

Dynamically add data to series in Highcharts

javascripthighcharts

提问by jgm196

I′m trying to update my highchart serie appending new data.

我正在尝试更新我的 highchart 系列并附加新数据。

My series look like:

我的系列看起来像:

series: [{
        name: 'Serie1',
        data:[
            {
                x: 0,
                low: Date.UTC(2013, 07, 03, 0, 00, 00),
                high: Date.UTC(2013, 07, 03, 4, 0, 0),
                cliente:[{nombre:'Pepe',
                    Partida:'11111',
                    Bandejas:'35'},
                    {nombre:'Pepe1',
                    Partida:'222',
                    Bandejas:'50'}]
            },
            {
                x: 0,
                low: Date.UTC(2013, 07, 03, 5, 0, 0),
                high: Date.UTC(2013, 07, 03, 9, 0, 0)
            },
                            {
                x: 0,
                low: Date.UTC(2013, 07, 03, 18, 0, 0),
                high: Date.UTC(2013, 07, 03, 24, 0, 0)
            }
      ]
    },
        {
        name: 'Serie2',
        data:[
            {
                x: 2,
                low: Date.UTC(2013, 07, 03, 4, 0, 0),
                high: Date.UTC(2013, 07, 03, 10, 0, 0)
            },
                            {
                x: 2,
                low: Date.UTC(2013, 07, 03, 18, 0, 0),
                high: Date.UTC(2013, 07, 03, 24, 0, 0)
            },
                            {
                x: 2,
                low: Date.UTC(2013, 07, 03, 0, 0, 0),
                high: Date.UTC(2013, 07, 03, 2, 0, 0)
            },
                            {
                x: 2,
                low: Date.UTC(2013, 07, 03, 11, 0, 0),
                high: Date.UTC(2013, 07, 03, 18, 0, 0)
            }
      ]
    }          
            ]

When I click a button I want to append new data inside "Serie 1".

当我单击一个按钮时,我想在“Serie 1”中附加新数据。

I′ve tried chart.series[pos].setData(newdata); and it works, but delete all the previous data. I′ve also tried using chart.series[pos-1].data.push(newdata); but it doesn′t work.

我试过 chart.series[pos].setData(newdata); 它可以工作,但删除所有以前的数据。我也试过使用 chart.series[pos-1].data.push(newdata); 但它不起作用。

Any solution?

有什么解决办法吗?

回答by Sebastian Bochan

You can use addPointfunction which allows to add new data.

您可以使用允许添加新数据的addPoint函数。