admin管理员组文章数量:1291083
I am trying to figure out the best way to dynamically clear/reset an AmChart. I have the following chart:
amchart = new AmCharts.AmSerialChart();
I have tried simply re-initializing it to clear it for rewriting but it fails with the chart going a solid gray. The best luck I have had has been calling specific functions and resetting specific attributes such as follows:
amchart.titles = [];
amchart.clearLabels();
I have used the API as a guide:
When the graph is rewritten it looks largely ok but some elements such as the side label are off. I have noticed this only when a legend is present. Can anyone help?
I am trying to figure out the best way to dynamically clear/reset an AmChart. I have the following chart:
amchart = new AmCharts.AmSerialChart();
I have tried simply re-initializing it to clear it for rewriting but it fails with the chart going a solid gray. The best luck I have had has been calling specific functions and resetting specific attributes such as follows:
amchart.titles = [];
amchart.clearLabels();
I have used the API as a guide: http://docs.amcharts./2/javascriptcharts/AmChart
When the graph is rewritten it looks largely ok but some elements such as the side label are off. I have noticed this only when a legend is present. Can anyone help?
Share Improve this question edited Jun 23, 2014 at 17:33 dustyhoppe 1,81317 silver badges20 bronze badges asked May 15, 2014 at 20:00 GedalyaGedalya 9094 gold badges16 silver badges32 bronze badges4 Answers
Reset to default 4To clear a chart with multiple data series, keep removing the first series until there are none left.
while(chart.series.length) {
chart.series.removeIndex(0).dispose();
}
The link posted by @Laurent is useful: https://www.amcharts./docs/v4/tutorials/dynamically-adding-and-removing-series/
Note that the key (or id) of the old series is retained in the chart's map. So you can't create a new series with the same id. In that case, you may prefer to just empty the series' data [].
const series = chart.series.getIndex(indexToRemove);
series.data = [];
Depending on what you're trying to acplish, Id consider trying:
amchart.validateNow();
// or
amchart.validateData();
After setting the properties and/or data provider on your chart.
Remove the series by using
chart.series.removeIndex(0);
Check here : https://www.amcharts./docs/v4/tutorials/dynamically-adding-and-removing-series/
To clear a chart simply use chart.clear();
本文标签: javascriptHow can I reset an AmChartStack Overflow
版权声明:本文标题:javascript - How can I reset an AmChart? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741519237a2383079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论