[英]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
的默認樣式引起的,其中所有單個點都繪制為實心圓。 這非常耗時,而且當您面對的點數太多時也不是特別實用。
不久前,我在自己的代碼中通過代碼隱藏解決了這個問題,將DataPointStyle
的TemplateProperty
更改為null
,然后通過將一些SolidColorBrush
分配給DataPointStyle
的BackgroundProperty
來定義線條顏色。
不幸的是,我沒有相應的 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.