javascripthighcharts

remove series by name or id in highcharts


Is there anyway to remove a series by name or id? I mean it is possible to remove series by this.remove()

or

var seriesLength = chart.series.length;
for(var i = seriesLength - 1; i > -1; i--) {
    chart.series[i].remove();
}

but by name say, series_name.remove() is it possible?


Solution

  • Ok, I found it myself. I send the series name in a hidden field of a div and when I click the delete button I'm checking if the name matches among the series and if match found I delete it.

    var chart = $('#container').highcharts();
                    var seriesLength = chart.series.length;
                    for(var i = seriesLength - 1; i > -1; i--)
                    {
                        //chart.series[i].remove();
                        if(chart.series[i].name ==document.getElementById("series_name").value)
                            chart.series[i].remove();
                    }