开发者

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 a开发者_如何转开发ny help!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜