简体   繁体   English

动态更改 Highcharts 中系列的数据

[英]Changing data dynamically for a series in Highcharts

I have a chart working fine with data in the options, when I leave the data empty for a series and try the below (so I can change the data depending on a click) it doesn't work, any ideas?我有一个图表可以很好地处理选项中的数据,当我将一个系列的数据留空并尝试以下操作(以便我可以根据单击更改数据)时,它不起作用,有什么想法吗?

options.series[0].data = [35.00,35.91,36.82,37.73,38.64];
var chart = new Highcharts.Chart(options);

you can also go with series.setData() .你也可以使用series.setData() This will allow you to change the entire data of a particular series.这将允许您更改特定系列的整个数据。

Here is the API link for it.这是它的 API 链接

Hope this will be of use for you.希望这对你有用。

You can update the values dynamically as follows :您可以按如下方式动态更新值:

chart.series[0].setData([89,71,16,12,14]);

If you want to change both value and label, create an array of arrays:如果要更改值和标签,请创建一个数组数组:

chart.series[0].setData([['Apple',89], ['Orange',71], ['Banana',16], ['Grapes',12], ['Others',14]]);

JSFiddle Demo to update data on a button click. JSFiddle Demo在单击按钮时更新数据。

Eureka - 需要嵌套的方括号,所以下面的工作..

options.series[0].data = [[35.00,35.91,36.82,37.73,38.64]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM