【问题标题】:Performance of WPF Toolkit Line ChartWPF 工具包折线图的性能
【发布时间】:2013-05-23 19:44:08
【问题描述】:

我刚刚使用绑定到List<KeyValuePair<int, float>> 的WPF 工具包创建了一个简单的图表。列表中大约有 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 编写了一个简单的图表,它可以立即绘制所有这些东西。请原谅我的无知,因为我对这些主题一无所知,但是导致这种性能差异的原因是什么?

【问题讨论】:

    标签: c# wpf performance charts wpftoolkit


    【解决方案1】:

    为了扩展 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>
    

    【讨论】:

      【解决方案2】:

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

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

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

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

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

      【讨论】:

      • 这绝对有帮助,但仍然很慢。非常感谢您抽出宝贵时间,我想我会检查其他选项。
      • 这可以在 XAML 中相当容易地完成,我在下面添加了一个答案。 :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      • 2016-04-18
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      相关资源
      最近更新 更多