积极答复者
Toolkit Chart的图像载入效率能否优化

问题
-
用Toolkit Chart做图像绘制,假设需要载入的点有一千多个,用LineSeries样式进行绘制,每幅图绘制时间约需要3s,如果去除掉点的样式,绘制时间大概可以到0.8s,但于操作而言,还是有卡一下的感觉出现。对比了一下其他一些用winform做的程序,他们绘制同等数量级图像的时间几乎可以忽略不计,对比了两者的图像生成,有如下差别:
WPF Toolkit Chart
其他程序图像:
貌似他们在绘制连续曲线的时候,是采用了近似的方法,对比前边点的样式对载入效率的影响,我想也许这种图像绘制方式是导致效率差异的一个主要地方。通过何种思路可能在Toolkitchart中也达到这样的效率呢?
Toolkit Chart绘制折线图的XAML:
<Window x:Class="LoadLine2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dc="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:dv="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" xmlns:cp="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Style x:Key="MyDataPointStyle" TargetType="dc:LineDataPoint"> <Setter Property="Background" Value="Blue"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="dc:LineDataPoint"/> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <dc:Chart Name="toolkitChart" Background="Transparent"> <dc:Chart.Series> <dc:LineSeries Name="LineCreate" ItemsSource="{Binding}" IndependentValueBinding="{Binding X}" DependentValueBinding="{Binding Y}" DataPointStyle="{StaticResource MyDataPointStyle}"> </dc:LineSeries> </dc:Chart.Series> </dc:Chart> <Button Content="Load" Height="27" Margin="19,13,0,0" Name="loadBtn" Width="71" Click="loadBtn_Click" /> </Grid> </Window>
答案
-
你好,wanto_com
在中文资料中很少能看到这类WPF Toolkit Chart performance的文章,所以我找到下面这篇英文blog,给出了几点可以优化WPF Chart performance的Tips 并包含例子程序,你可以下载以作参考, http://blogs.msdn.com/b/delay/archive/2010/01/13/i-feel-the-need-the-need-for-speed-seven-simple-performance-boosting-tweaks-for-common-silverlight-wpf-charting-scenarios.aspx
希望对你有所帮助。
Annabella Luo[MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 Annabella LuoModerator 2012年9月24日 11:53
- 已标记为答案 Min ZhuModerator 2012年10月9日 9:17
全部回复
-
你好,wanto_com
在中文资料中很少能看到这类WPF Toolkit Chart performance的文章,所以我找到下面这篇英文blog,给出了几点可以优化WPF Chart performance的Tips 并包含例子程序,你可以下载以作参考, http://blogs.msdn.com/b/delay/archive/2010/01/13/i-feel-the-need-the-need-for-speed-seven-simple-performance-boosting-tweaks-for-common-silverlight-wpf-charting-scenarios.aspx
希望对你有所帮助。
Annabella Luo[MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 Annabella LuoModerator 2012年9月24日 11:53
- 已标记为答案 Min ZhuModerator 2012年10月9日 9:17
-
你好,
我认为你的理解是正确的,在loading的时候以减少Inotification触发的次数来使Chart实现一次性加载。但是ObservableCollection是一个可以自动完成INotification的数据类型,在文档中的AddRangeObservableCollection方法中,在添加所有的Item到Collection中后作者手动的触发了Notification的机制,但是这并没能阻止在添加每个Item到ObservableCollection中时其自动触发的Notification机制。就是说,你可能需要使用List<object>这样的数据类型,在其中添加手动Notification的机制来达到这样的目的。
希望我的理解对你有所帮助。
Annabella Luo[MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 Annabella LuoModerator 2012年9月24日 11:53