DynamicDataDisplay ChartPlotter 删除所有绘图

Cyn*_*cal 5 c# wpf charts dynamic-data-display

在我的 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>
Run Code Online (Sandbox Code Playgroud)

其中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");
Run Code Online (Sandbox Code Playgroud)

我现在想做的是删除该图并使用不同的点集重新绘制它。不幸的是,我无法在 D3 的(糟糕的)文档和网络中找到任何朝着这个方向发展的内容。

关于做什么或去哪里看有什么建议吗?

谢谢!

Jas*_*ins 2

我发现执行此操作的最佳方法是在后面的代码中拥有一个代表数据源的属性,并将图表的数据源绑定到该属性。让您的代码实现 INotifyPropertyChanged 并在每次更新或重新分配数据源时调用 OnPropertyChanged。这将迫使绘图仪观察绑定并重新绘制图形。

例子:

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));
} 
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,我能找到的最佳资源是 D3 所在的 CodePlex 讨论: 讨论