0

I have a C# WinForms app which displays the chart. Every time the source data changes, I do

foreach (var s in chart.Series)
    s.Points.Clear();
foreach (var item in sourceData)
    chart.Series["Prsr"].Points.AddY(item.Prsr);

The problem is that the souceData may have over 30k items. Above method in my case blocks the UI for over 1 second.

Does anyone know any better method to avoid the problem?

sourceData is a List<obj>

I also tried with the DataBindY:

chartMain.Series["Prsr"].Points.DataBindY(sourceData, "Prsr");

but it didn't help.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
LUK
  • 1
  • 1
  • 1
  • Have you tried `SuspendLayout` and `ResumeLayout`. It may prevent any attempts to redraw the control during the update. You may see some advantage if you were to slow things down, with by doing an `await Task.Delay(1);` every N points – Flydog57 Feb 15 '23 at 23:17
  • 3
    Your chart probably doesn't need 30K items. Find a way to reduce that for visual purposes. – LarsTech Feb 15 '23 at 23:27
  • Since the lag occurs while also using the `DataBindY` method that internally uses the `Points.SuspendUpates` method, I suspect that the `Points.Clear` method is the cause. Does this answer your question? [DataPointCollection Clear performance](https://stackoverflow.com/questions/5744930/datapointcollection-clear-performance) – TnTinMn Feb 16 '23 at 03:59

1 Answers1

0

Thx you all very much.

First I've tested the @TnTinMn suggestion (Points.SuspendUpdates and clearing all points in a loop instead od Points.Clear). It shortened the time of clearing the example chart from 400ms to 15ms. Very big improvement, but this is just half of the total time the UI was blocked.

Then the suggestion from @Flydog57 - suspendUpdate() when adding points shortened the time by almost 300ms. Another big improvement.

Now the next step will as suggested by @LarsTech - reducing the number of samples to display (divide into data ranges and calculate the average for each range). Why didn't I think about it?

Thank you all once again.

LUK
  • 1
  • 1
  • 1