luftikus143
luftikus143

Reputation: 1285

How to remove a series in Highcharts by name

I'd like to remove certain series from my Highcharts graph when a user clicks on a button. But I'd like to delete these by using a name or id of the series, and not the item in an array.

So, instead of doing this:

    chart.series[1].remove();

I'd like to use:

    chart.series["Volcanoes"].remove();

However, I don't succeed in this. Anything wrong with this here:

    chart.addSeries(
    {
        name: "Volcanic",
        id: "Volcanic",
        data: [xxxx]
    });

Or how do I access the series by name? Here is a fiddle.

Upvotes: 2

Views: 3047

Answers (1)

hsh
hsh

Reputation: 1855

In order to get a seri by ID you should use chart.get("SeriId") and to remove it use below code:

chart.get('Volcanic').remove();

I edited your sample with this approach Here

Upvotes: 4

Related Questions