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

泪湿孤枕 提交于 2020-01-01 05:14:29

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5906897/chart-control-in-c-sharp-net-uses-tons-of-cpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!