[英]Performance of WPF Toolkit Line Chart
I have just created a simple chart using WPF Toolkit that binds to a List<KeyValuePair<int, float>>
.我刚刚使用绑定到
List<KeyValuePair<int, float>>
WPF Toolkit 创建了一个简单的图表。 There are around 16,000 points in the list.列表中有大约 16,000 个点。 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.我知道有人用 Windows 窗体中的
BufferedGraphics
编写了一个简单的图表,并且它立即绘制了所有这些东西。 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:为了扩展 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>
If I am not mistaken, this is caused by the default style for the LineSeries
, where all individual points are drawn as filled circles.如果我没记错的话,这是由
LineSeries
的默认样式引起的,其中所有单个点都绘制为实心圆。 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
.不久前,我在自己的代码中通过代码隐藏解决了这个问题,将
DataPointStyle
的TemplateProperty
更改为null
,然后通过将一些SolidColorBrush
分配给DataPointStyle
的BackgroundProperty
来定义线条颜色。
Unfortunately, I do not have a corresponding XAML solution.不幸的是,我没有相应的 XAML 解决方案。 (I am not even sure if it can be easily done in XAML?).
(我什至不确定它是否可以在 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)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.