Search code examples
c#wpfperformancechartswpftoolkit

Performance of WPF Toolkit Line Chart


I have just created a simple chart using WPF Toolkit that binds to a List<KeyValuePair<int, float>>. There are around 16,000 points in the list. It takes the charting control incredibly long to draw it (I have stopped waiting after a minute.)

Here's the code:

<chartingToolkit:Chart DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=MyData}">
    <chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}"/>
</chartingToolkit:Chart>

Is this performance normal for this charting control or am I doing something wrong? If so how can I improve the performance?

I know someone who has written a simple chart with just using BufferedGraphics in Windows Forms, and it was drawing all these things instantly. Please excuse my ignorance, as I know nothing regarding these subjects, but what is causing this performance difference?


Solution

  • If I am not mistaken, this is caused by the default style for the LineSeries, where all individual points are drawn as filled circles. This is incredibly time consuming and also not particularly practical when you have the number of points you are facing.

    I solved this through code-behind in my own code a while ago, by changing the TemplateProperty of the DataPointStyle to null, and then defining the line color by assigning some SolidColorBrush to the BackgroundProperty of the DataPointStyle.

    Unfortunately, I do not have a corresponding XAML solution. (I am not even sure if it can be easily done in XAML?).

    Here is an example snippet from my code-behind. I hope it should give you a push in the right direction:

    var viewSeries = new LineSeries
    {
        DataPointStyle = new Style
        {
            TargetType = typeof(DataPoint),
            Setters = { new Setter(TemplateProperty, null) }
        }
    };
    viewSeries.DataPointStyle.Setters.Add(
        new Setter(BackgroundProperty, new SolidColorBrush(Colors.Red)));