在我的WPF應用程序中,我有一個D3 ChartPlotter,我可以繪製4個LineGraphs。這是XAML代碼:DynamicDataDisplay ChartPlotter刪除所有地塊
<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>
其中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和(網絡)的(窮人)文檔中找到那個方向的任何內容。
任何有關該做什麼或在哪裏尋找的建議?
謝謝!
謝謝你的回答,@Jason。由於我對所有D3事物(以及一般的WPF)都很陌生,請問您能否使用XAML代碼的示例?我必須綁定單個'xCoord'和'yCoord',還是CompositeDataSource就夠了? – Cynical
好吧,我想我已經解決了,在討論@Jason Higgins中提到的更深入: private void ClearPlotter(){{ MarkerPointsGraph).ToArray()){this.plotter.Children.Remove(elem); } } 您認爲這是一個很好的解決方案嗎? – Cynical
如果您的意思是清除該圖以顯示新數據,則不需要刪除所有元素!只需將您創建的DataSource屬性設置爲新集合,然後調用Property Changed Event,然後它將自動更新綁定。如果你的意思是隻清除你的圖並且不顯示任何數據,把你的DataSource設置爲一個空集合。即。 D3DataSource = new EnumerableDataSource(new object [0]); –