I am working on a WPF app that uses OxyPlot.
I've followed the example. I am successfully plotting a chart using the following XAML:
<oxy:Plot Height="640" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding ResultSet1}" />
<oxy:LineSeries ItemsSource="{Binding ResultSet2}" />
<oxy:LineSeries ItemsSource="{Binding ResultSet3}" />
</oxy:Plot.Series>
</oxy:Plot>
My ViewModel looks like this:
public class MyViewModel
{
public IList<DataPoint> ResultSet1 { get; set; }
public IList<DataPoint> ResultSet2 { get; set; }
public IList<DataPoint> ResultSet3 { get; set; }
public void Load()
{
this.ResultSet1 = new List<DataPoint>
{
new DataPoint(0, 4),
new DataPoint(40, 12),
new DataPoint(50, 12)
};
this.ResultSet2 = new List<DataPoint>
{
new DataPoint(-0.4, 3),
new DataPoint(8, 12),
new DataPoint(48, 11)
};
this.ResultSet3 = new List<DataPoint>
{
new DataPoint(2, 5),
new DataPoint(12, 14),
new DataPoint(52, 13)
};
}
public void Refresh()
{
this.ResultSet1 = new List<DataPoint>();
this.ResultSet2 = new List<DataPoint>();
this.ResultSet3 = new List<DataPoint>();
System.Windows.MessageBox.Show("should be empty");
}
}
In my code, I have a "Refresh" button. When a user clicks that, I'm trying to refresh the data that's displayed. However, its like the results are not getting updated in the UI. I added the MessageBox
shown above, to ensure that i was actually getting into the Refresh
method. That message box appears. So, at this point, I know:
a) The OxyPlot chart is working because my initial result set values that are hard-coded are appearing fine.
b) I've successfully wired-up the view model.
c) I'm getting into the Refresh
method.
I'm just not sure why the points on the chart do not seem to be refreshing. Any insights are appreciated!
instead of using IList
use ObservableCollection
public ObservableCollection<DataPoint> ResultSet1 { get; set; }
public ObservableCollection<DataPoint> ResultSet2 { get; set; }
public ObservableCollection<DataPoint> ResultSet3 { get; set; }
and instead of using new IList<T>()
use
ResultSet1.Clear();
ResultSet2.Clear();
ResultSet3.Clear();