Click here to Skip to main content
15,889,403 members
Articles / Programming Languages / C#

Speedup MSChart Clear Data Points

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
30 Apr 2012MIT 16.1K   3   2
Speedup MSChart Clear Data Points

Problem Statement

Clearing data points in MSChart is known to be very slow.

Solution

However, there is a workaround for this problem. The suggested workaround from link stated above is as below:

C#
public void ClearPointsQuick()
{
    Points.SuspendUpdates();
    while (Points.Count > 0)
        Points.RemoveAt(Points.Count - 1);
    Points.ResumeUpdates();
    Points.Clear(); //NOTE 1
}

Extension method implementation is as below:

C#
internal static class MSChartExtension
{
    public static void ClearPoints(this Series sender)
    {
        sender.Points.SuspendUpdates();
        while (sender.Points.Count > 0)
            sender.Points.RemoveAt(sender.Points.Count - 1);
        sender.Points.ResumeUpdates();
        sender.Points.Clear(); //NOTE 1
    }
}

(NOTE 1): I added one additional line Points.Clear() at the end of the function to ensure the chart axis updated correctly on next plot. Without adding this line, I observed that previous axis settings will be used when plotting new data points right after calling ClearPoints().

See Also

MSChart Extension: An extension package for MSChart component which contains these fixes and other features.

Revision History

  • 31/03/2012: Added additional line to force axis update on next plot (NOTE 1)
  • 12/03/2012: Initial release

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Technical Lead
Malaysia Malaysia
Official Page: www.codearteng.com

Comments and Discussions

 
GeneralMy vote of 5 Pin
JF201511-Jan-18 0:58
JF201511-Jan-18 0:58 
GeneralRe: My vote of 5 Pin
Code Artist11-Jan-18 3:28
professionalCode Artist11-Jan-18 3:28 
Thank you.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.