mahtikebab
Posts: 6
Joined: Thu Aug 09, 2018 12:09 pm

Best way to delete old data from live updated chart

Hi,
I have a chart that gets updated every 20 ms. New data gets added via series.addPoint(). After a while the site crashes and I think it's because highcarts gets too many points to store. What would be the best way to remove this old data that's no longer shown? I need about 500 points per series so I would like to delete all the points that surpass that limit, so the deletion is not visible in UI. I could probably store the data I receive in an array and just call series.setData() with the 500 points every 10 seconds or something. Alternatively I could remove a point when I add a point but I assume this could have negative performance effects? Could I slice the series.data somehow maybe? I tried series.setData(series.data.slice(-500)) but it didn't seem to work properly
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Best way to delete old data from live updated chart

Hi, mahtikebab!

The simplest way is to use addPoint() method with a second true argument. You can read more about it here in docs: https://api.highcharts.com/class-refere ... s#addPoint

Live example: https://jsfiddle.net/BlackLabel/evypfr1L/

Best regards!
Rafal Sebestjanski,
Highcharts Team Lead
mahtikebab
Posts: 6
Joined: Thu Aug 09, 2018 12:09 pm

Re: Best way to delete old data from live updated chart

Hi Rafal,
thank you for your reply This seems to be exactly what I was looking for. I assumed I had missed some simple config switch to do this, hence I wanted to ask the question. I take it the "shift" argument works so that we can have the live data page open for days without memory overflow?

Thanks!
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Best way to delete old data from live updated chart

mahtikebab,

I have never tested a live data chart for a few days, but I assume that, yes, it should work as expected without any problems. addPoint() method with shift argument will remove old data and should not store it in memory anymore. In case of any problems - let us know.

Kind regards!
Rafal Sebestjanski,
Highcharts Team Lead
teixeirel
Posts: 20
Joined: Fri Apr 24, 2020 10:47 am

Re: chart.series[0].data.length problem

Hello,
My chart.series[0].data.length reaches 454 and stop increment, but new points still appear in the chart. Why is this happening?
Imagine that I want 500 points like the example, with this problem i can't delete oldest points.
piotr.m
Posts: 1433
Joined: Mon Nov 18, 2019 8:15 am

Re: Best way to delete old data from live updated chart

Hi teixeirel,

I saw that you created a new topic related to this matter, so let's continue here:
viewtopic.php?f=12&t=44058#p155850

Kind Regards
teixeirel
Posts: 20
Joined: Fri Apr 24, 2020 10:47 am

Re: Best way to delete old data from live updated chart

Thanks!
I wrote there.
Peña00
Posts: 2
Joined: Tue Nov 24, 2020 7:42 am

Re: Best way to delete old data from live updated chart

Thanx for all, that was to simple but i didnt find it :D
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Best way to delete old data from live updated chart

In case of any further questions feel free to contact us any time!
Paweł Lysy
Highcharts Developer

Return to “Highcharts Usage”