Anders
Anders

Reputation: 17554

refresh WPF D3 Dynamic Data display Chart

I databind the LineGraph with a datasource when new points comes from backend, the problem is that the grid isnt refreshed, you can do a plotter.FitToView() to get it to refresh but that also fits the new graph to the plotter window this is very irretating if you have zoomed in and panned to a specific point on the chart because it will zooom out to fit the graph on the chart... So, is there a way to refresh it after databind (You think that a databind would refresh it+..

I can also consider changing WPF chart enterily i have one requirement and its that you can define draggable points on the chart

Upvotes: 0

Views: 3814

Answers (3)

Ross Llewallyn
Ross Llewallyn

Reputation: 68

Have you tried reassigning the data collection when you add new data? I noticed this was necessary to update my graph. For example, after adding new objects to my collection, I'd use this:

DataCollection = new ObservableCollection<DataObject>(DataCollection);

This started working, and I thought it was because the chart only responded to OnPropertyChanged and not OnCollectionChanged, or something to that effect. The line is painfully pointless and slows down the display for large amounts of data, though.

Edit: This is including Jason's answer above to notify of changes!

Upvotes: 0

Jason Higgins
Jason Higgins

Reputation: 1526

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));
} 

Upvotes: 1

ColinE
ColinE

Reputation: 70122

The interface to the WPF D3 chart is entirely programmatic, i.e. you have to 'push' updates rather than use binding to automatically refresh the UI. As an alternative perhaps consider Visiblox chart, there is a blog post here which describes how to make datapoints draggable as you require:

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

Disclosure: I work for the company that created Visiblox charts.

Upvotes: 0

Related Questions