How to refresh oxyplot plot when data changes

前端 未结 7 1460
予麋鹿
予麋鹿 2021-02-07 02:10

\"GUI

Oxyplot graphs 13 points which are derived from the 6 user input text boxes. The values in

7条回答
  •  半阙折子戏
    2021-02-07 02:44

    In the current OxyPlot.Wpf (1.0.0-unstable1983) you have two options:

    1. Bind the Series.ItemsSource property from XAML to a collection in your viewmodel and exchange the whole collection, when you need an update. This also allows for concurrent async updates with larger data sets.
    2. Bind the Plot.InvalidateFlag property of type int to your viewmodel and increment whenever you need an update. I haven't tested this approach, though.

    The following code illustrates both options (pick one). XAML:

    
        
            
          
     
    

    Updates on the ViewModel:

    private async Task UpdateAsync()
    {
        // TODO do some heavy computation here
        List data = await ...
    
        // option 1: Trigger INotifyPropertyChanged on the ItemsSource.
        //           Concurrent access is ok here.
        this.DataSeries = data; // switch data sets
    
        // option 2: Update the data in place and trigger via flag
        //           Only one update at a time.
        this.DataSeries.Clear();
        data.ForEach(this.DataSeries.Add);
        this.InvalidateFlag++;
    }
    

提交回复
热议问题