在我的 WPF 应用程序中,我有一个 D3 ChartPlotter,可以在其中绘制 4 个折线图。这是 XAML 代码:
<d3:ChartPlotter Name="plotter">
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalAxis Name="timeAxis" />
</d3:ChartPlotter.HorizontalAxis>
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalAxis Name="accelerationAxis" />
</d3:ChartPlotter.VerticalAxis>
</d3:ChartPlotter>
where d3
是 DinamicDataDisplay 的命名空间,这是背后的代码(相关部分)。
var x = new List<int>();
var y = new List<int>();
for (var t = 0; t <= 10; t = t + 1) {
x.Add(t);
y.Add(Math.Pow(t,2));
}
var xCoord = new EnumerableDataSource<int>(x);
xCoord.SetXMapping(t => t);
var yCoord = new EnumerableDataSource<int>(y);
yCoord.SetYMapping(k => k);
CompositeDataSource plotterPoints = new CompositeDataSource(xCoord, yCoord);
plotter.AddLineGraph(plotterPoints, Brushes.Red.Color , 2, "MyPlot");
我现在想做的是删除该图并使用不同的点集重新绘制它。不幸的是,我无法在 D3 的(糟糕的)文档和网络中找到任何朝着这个方向发展的东西。
关于做什么或去哪里看有什么建议吗?
Thanks!
我发现执行此操作的最佳方法是在后面的代码中拥有一个代表数据源的属性,并将图表的数据源绑定到该属性。让您的代码实现 INotifyPropertyChanged 并在每次更新或重新分配数据源时调用 OnPropertyChanged。这将迫使绘图仪观察绑定并重新绘制图形。
Example:
EnumerableDataSource<Point> m_d3DataSource;
public EnumerableDataSource<Point> D3DataSource {
get {
return m_d3DataSource;
}
set {
//you can set your mapping inside the set block as well
m_d3DataSource = value;
OnPropertyChanged("D3DataSource");
}
}
protected void OnPropertyChanged(PropertyChangedEventArgs e) {
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) {
handler(this, e);
}
}
protected void OnPropertyChanged(string propertyName) {
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
如果您需要更多信息,我能找到的最佳资源是 D3 所在的 CodePlex 讨论:讨论 http://dynamicdatadisplay.codeplex.com/discussions
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)