C# – How to draw line of ten thousands of points with WPF within 0.5 second

c++itemscontrolperformancetemplateswpf

I am writing WPF code to show a real-time plot which is a connected line containing about
10,000 points. It takes about 5 seconds to show a picture in my computer. Does anyone have an idea to make it quicker and within 0.5 second?

class eee : FrameworkElement
{

    public eee()
    {
        _children = new VisualCollection(this);
        Random rand = new Random();
        DrawingVisual dv = new DrawingVisual();
        using (DrawingContext dx = dv.RenderOpen())
        {
            Pen drawingPen = new Pen(Brushes.Black, 1);
            double x=rand.Next(300);
            double y = rand.Next(300);
            for (double i = 0; i < 1000; i = i + 0.1)
            {
                y = 100 + rand.Next(100);
                dx.DrawLine(drawingPen, new Point(i, x), new Point(i + 1, y));
                x = y;
            }
        }
         _children.Add(dv);
    }

Best Solution

Charles Petzold does exactly that. It is even faster on my host (< 0.3 secs), and the point's are even DataBound!! ;)

Tamir Khason does this also, with lines and goes into more depth about Bitmap style performance WPF here.

Rico Mariani has some guidance for 3D high performance graphics, essentially leveraging value types can improve your throughput if well thought out.

Jianzhong Zhang gives my new favourate tutorials on this subject, 3D scatter plot several tens of thousands of data points animated and interactive.