Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart Control in C# (.NET) Uses Tons of CPU

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!

like image 775
NJC Avatar asked May 06 '11 04:05

NJC


People also ask

Is c-chart control chart?

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.

How do you calculate C on a control chart?

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.

What is control chart with Example?

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.


2 Answers

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.

like image 103
RogueBudz Avatar answered Sep 22 '22 03:09

RogueBudz


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.

like image 41
IAmTimCorey Avatar answered Sep 22 '22 03:09

IAmTimCorey