I am using a FastLineChart in C# to display a signal from an external device in real time. The sample rate is about 700Hz. In my program I down-sample to about 100Hz to minimize unnecessary resolution for the display, but still use way too much CPU doing this.
I think the problem is that I am scrolling the data across the chart (like the CPU graph does in windows) and this is eating up resources. I do this by removing the oldest element and then adding a new one to the specific series (as shown below).
timeGraph.Series[0].Points.RemoveAt(0);
timeGraph.Series[0].Points.AddY(average);
The CPU load is about 30% which I think is a bit too high. I do not have the newest computer, but it is a Code 2 Duo with GT9600 graphics card.
Does anyone have any suggestions? Is there a better way to do this? Or a specific way to make this faster?
Thank you for any help!
A c-chart is an attributes control chart used with data collected in subgroups that are the same size. C-charts show how the process, measured by the number of nonconformities per item or group of items, changes over time.
The c chart formulas are (Doty, 1996): Number of defects per unit c = Σc / Σn = Σc / m. Upper control limit (UCL) = c + 3√c. Lower control limit (LCL) = c – 3√c.
The control chart is a graph used to study how a process changes over time. Data are plotted in time order. A control chart always has a central line for the average, an upper line for the upper control limit, and a lower line for the lower control limit. These lines are determined from historical data.
Ok, so old question to answer, but i was stuck with a problem similar to this for ages, so for anyone who finds this:
To stop the massive CPU usage:
1) declare an integer
int graphUdate = 0;
2) in form_ load, add
chart1.Series.SuspendUpdates();
3) when adding a point to your graph, use
graphUpdate++;
4) in the same space, update the graph every # number of points and reset graphUpdate
if (graphUpdate == #)
{
chart1.Series.ResumeUpdates();
chart1.Series.Invalidate();
chart1.Series.SuspendUpdates();
graphUpdate = 0;
}
this updates all point gathered since the last chart1.Series.SuspendUpdates();
the removal of points will also be suspended, making a MAJOR difference to CPU usage.
I would suggest that the issue might be that you are using Winforms. GDI+ is fairly slow when dealing with animated graphics. If possible, moving to WPF will definitely help. However, if the chart control does not take advantage of the graphics card, you might need to look into a different control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With