Eric - 2012-07-31

Hi
I have found a problem when adding and removing series in the chart.

The following happens
i have created 2 series and add them to the chart, i see 2 series in my chart.
Then i remove all series and create and add 3 series. I see 3 series in the chart
Finally i remove all and create 2 series. I see 3 series in the chart

Unfortunatly i am not an expert to simultae this code on the fly but i think i have found where the problem come from.

In BaseChart, when the chart is display the foloowing code is ran

// #2: We need to setup whatever data series needs to be rendered initially in the chart
    if (seriesList.size() > 0) {
        final JSONValue seriesValue = options.get("series");
        if (seriesValue == null || seriesValue.isArray() == null) {
            options.put("series", new JSONArray());
        }
        final JSONArray seriesArray = (JSONArray) options.get("series");
        for (int i = 0, seriesListSize = seriesList.size(); i < seriesListSize; i++) {
            Series series = seriesList.get(i);
            JSONObject seriesOptions = convertSeriesToJSON(series);
            seriesArray.set(i, seriesOptions);
        }
    }

a quick look show that seriesValue contains the first time 2 entries, then 3 entries, and stays at 3 entries.
The highChart creates and add series by reading this options object (method init() then firstRender())
// Initialize the series
each(options.series || [], function (serieOptions) {
chart.initSeries(serieOptions);
});

Which explain why 3 series are displayed instead of 2.
a simple

highCharts.removeAllSeries(false);
JSONObject options = highCharts.getOptions();
options.put("series", new JSONArray());

will effectivly remove all Series.

Do you think you can correct this fir the futur version ?

thanks