luftikus143 luftikus143 - 5 months ago 88
Javascript Question

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.

Thanks for any hint!

hsh hsh
Answer

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