简体   繁体   中英

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?

To extend Anders Gustafsson's answer, this can be done in XAML as follows:

 <chart:LineSeries ItemsSource="{Binding}" DependentValueBinding="{Binding Path=x}" IndependentValueBinding="{Binding Path=y}">
  <chart:LineSeries.DataPointStyle>
    <Style TargetType="chart:LineDataPoint">
       <Setter Property="Template" Value="{x:Null}" />
    </Style>
  </chart:LineSeries.DataPointStyle>
</chart:LineSeries>

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)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM