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 badges
Add a ment  | 

4 Answers 4

Reset to default 4

To 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