0

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

Jason Higgins
  • 1,516
  • 1
  • 17
  • 37
Anders
  • 17,306
  • 10
  • 76
  • 144

3 Answers3

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));
} 
Jason Higgins
  • 1,516
  • 1
  • 17
  • 37
  • Yes thats how I do it, but I use Caliburn.Micro. Nothing happens and you need to use FitToView() to get it to refresh points – Anders Nov 19 '12 at 14:20
0

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!

Ross Llewallyn
  • 66
  • 2
  • 11
0

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.

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • Its for a open source project, cant use a pay product :/ – Anders Jan 05 '12 at 00:05
  • I've decided to give Visiblox a chance since its very databindable.. I looked at the example and copied the MovePointBehaviour code... It works.. But I need to capture when the point changes so that my bussiness logic can react to that, whats the best way of gettting that? – Anders Jan 05 '12 at 13:59