繁体   English   中英

WPF Toolkit 折线图的性能

[英]Performance of WPF Toolkit Line Chart

我刚刚使用绑定到List<KeyValuePair<int, float>> WPF Toolkit 创建了一个简单的图表。 列表中有大约 16,000 个点。 绘制图表控件需要非常长的时间(一分钟后我已经停止等待。)

这是代码:

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

这种图表控件的性能是否正常,还是我做错了什么? 如果是这样,我该如何提高性能?

我知道有人用 Windows 窗体中的BufferedGraphics编写了一个简单的图表,并且它立即绘制了所有这些东西。 请原谅我的无知,因为我对这些主题一无所知,但是是什么导致了这种性能差异?

为了扩展 Anders Gustafsson 的答案,这可以在 XAML 中完成,如下所示:

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

如果我没记错的话,这是由LineSeries的默认样式引起的,其中所有单个点都绘制为实心圆。 这非常耗时,而且当您面对的点数太多时也不是特别实用。

不久前,我在自己的代码中通过代码隐藏解决了这个问题,将DataPointStyleTemplateProperty更改为null ,然后通过将一些SolidColorBrush分配给DataPointStyleBackgroundProperty来定义线条颜色。

不幸的是,我没有相应的 XAML 解决方案。 (我什至不确定它是否可以在 XAML 中轻松完成?)。

这是我的代码隐藏中的示例片段。 我希望它能让你朝着正确的方向前进:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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