I have 3 different graph displays which make use of the MSChart library for C#. I am updating the graphs with data as it becomes available in real time. The function which updates the display runs approximately every 40ms, and goes something like this:
private void UpdateDisplay()
{
// Process data for graph 1
// (Graph 1 has 2 Line graphs, and 1 Candlestick)
// Get the series
Charting.Series lineGraph1 = graph1.Series[0];
// ....process s开发者_如何学编程ome data and generate new data....
// Update the data
for (int i = 0; i < displayedSamples; i++)
{
lineGraph1.Points[i].YValues[0] = newData[i];
// ....update other series' data....
}
// Redraw the graph
graph_1.Invalidate();
graph_1.Update();
// Process data for graph 2
// (Graph 2 has 1 bar graph)
// ...
graph_2.Invalidate();
graph_2.Update();
// Process data for graph 3 and update points
// (Graph 3 has 2 column graphs)
// ...
graph_3.Invalidate();
graph_3.Update();
}
Running the application causes the CPU usage for the app to skyrocket. If I remove only the "Invalidate()" calls, then the CPU usage for the application is close to 0%.
The set of points in the series stays consistent. All points are added when the series are generated, and then the values of the points are just updated.
I have tried to improve performance by only invalidating the points in the displayed series (i.e. graph_3.Series[0].Points.Invalidate()), but this has had no noticeable effect.
What are my options to improve the performance?
精彩评论