0

当新点来自后端时,我将 LineGraph 与数据源数据绑定,问题是网格未刷新,您可以执行 plotter.FitToView() 以使其刷新,但这也适合新图形到绘图仪窗口这是如果您放大并平移到图表上的特定点,这是非常令人讨厌的,因为它会缩小以适合图表上的图形......那么,有没有办法在数据绑定之后刷新它(您认为数据绑定会刷新它+..

我也可以考虑直接更改 WPF 图表我有一个要求,您可以在图表上定义可拖动的点

4

3 回答 3

1

The best way that I have found to do this, is to have a Property in your code behind that represents the DataSource and bind the chart's DataSource to that property. Have your code behind implement INotifyPropertyChanged and call OnPropertyChanged every time you update or re-assign your data source. This will force the plotter to observe the binding and redraw your graph.

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));
} 
于 2012-11-12T16:39:47.697 回答
0

您是否尝试在添加新数据时重新分配数据集合?我注意到这是更新我的图表所必需的。例如,在我的集合中添加新对象后,我会使用这个:

DataCollection = new ObservableCollection<DataObject>(DataCollection);

这开始起作用了,我认为这是因为图表只响应 OnPropertyChanged 而不是 OnCollectionChanged,或者类似的东西。但是,这条线毫无意义,并且会减慢大量数据的显示速度。

编辑:这包括上面杰森的回答,以通知更改!

于 2013-04-30T21:48:57.130 回答
0

WPF D3 图表的界面完全是程序化的,即您必须“推送”更新而不是使用绑定来自动刷新 UI。作为替代方案,也许可以考虑 Visiblox 图表,这里有一篇博客文章描述了如何根据需要使数据点可拖动:

http://www.visiblox.com/blog/2011/11/creating-a-custom-behaviour-part-3-the-finale

披露:我为创建 Visiblox 图表的公司工作。

于 2012-01-04T17:03:58.610 回答