How can I delete all of the points from a highcharts series

10,432

If you want to delete some points from your serie I sugest you to store your serie points, remove the points you want and then use setData to set your serie data again.

If you want to remove all points without remove the serie you can use chart.series[0].setData([]);.

You can use addPoint to add points one by one or setData for more than one.
There're some examples which shows how to do it.
demo
reference

Share:
10,432

Related videos on Youtube

djq
Author by

djq

Currently working for a large tech company in Dublin. Previously, a co-founder of a technology startup; there I worked with a small team using Python, Django, Django-Rest-Framework, Pandas (and more!). I've a background in urban analysis (geospatial data), stats (R) and data visualization (ggplot2, D3) Excited about how technology can be used for social good.

Updated on September 27, 2022

Comments

  • djq
    djq over 1 year

    Using HighCharts I want to delete all of the points from a series, so that I can add a new dataset. Is there a better approach than looping through all of the points, and removing them one by one like this?:

    for(var i=0; i < chart.series[0].points.length; i++){
        chart.series[0].points[i].remove()
    }
    

    I have also seen references to ways of removing the entire series chart.series[0].remove(); This seems quicker to remove the points, but I don't understand how to create an empty series with the same properties and name that points can be added to, which is why I chose to delete the points.

  • djq
    djq over 11 years
    chart.series[0].setData([]); worked - I did not realize an empty array could be passed in.