javascript Amcharts 如何在不重新加载整个图表的情况下将新图表数据推送到图表中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25891931/
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 05:11:12  来源:igfitidea点击:

Amcharts how to push new chart data into chart without reloading of whole chart?

javascriptamcharts

提问by redrom

I would like to replace new data in JSON to chart and display them in the chart without reload of whole canvas. Is it possible in AmCharts library and if yes, how can i do it?

我想将 JSON 中的新数据替换为图表并将它们显示在图表中,而无需重新加载整个画布。是否可以在 AmCharts 库中使用,如果是,我该怎么做?

Thanks for any advice.

感谢您的任何建议。

回答by Simon

Here is an example for you... http://jsfiddle.net/Se2UE/4/

这是你的一个例子...... http://jsfiddle.net/Se2UE/4/

I had a similar issue previously. You just need to add the data to a new array and update the graph. The key elements are:

我以前有过类似的问题。您只需要将数据添加到新数组并更新图形。关键要素是:

//New data array
var NewChartData = [];

//Adding new data to array
NewChartData.push(JSON.parse(D));

//Setting the new data to the graph
chart.dataProvider = NewChartData;

//Updating the graph to show the new data
chart.validateData();

For this example I just used data from a DIV element on the page but you can use the same method to get the data from another source.

对于本示例,我仅使用了页面上 DIV 元素中的数据,但您可以使用相同的方法从其他来源获取数据。