Currently I have a WPF with a single Oxyplot and three buttons that switch the data that will be displayed on the oxyplot. Each data set has three scatter series within it. So one PlotModel
and three sets of three ScatterSeries
Here is a pseudo code of what mine currently does. Please note that all DataLists contain different data so I know for a fact when the plot refreshes, the plot's not changing and not having the same value:
XML:
<Button Name="data1" Click="getData1"/>
<Button Name="data2" Click="getData2"/>
<Button Name="data3" Click="getData3"/>
<oxy:PlotView x:Name="Plot" Model="{Binding PlotModel}"/>
MainWindow:
private PlotModel plotModel;
public PlotModel PlotModel
{
get { return plotModel; }
set { plotModel = value; OnPropertyChanged("PlotModel"); }
}
public MainWindow()
{
PlotModel = new PlotModel();
setUp();
}
private void getData1()
{
updateModel(1, DataList1, DataList2, DataList3);
Plot.InvalidatePlot(true);
}
private void getData2()
{
updateModel(2, DataList4, DataList5, DataList6);
Plot.InvalidatePlot(true);
}
private void getData3()
{
updateModel(3, DataList7, DataList8, DataList9);
Plot.InvalidatePlot(true);
}
private void setUp()
{
PlotModel.LegendTitle = "Legend";
PlotModel.LegendOrientation = LegendOrientation.Horizontal;
PlotModel.LegendPlacement = LegendPlacement.Outside;
PlotModel.LegendPosition = LegendPosition.TopRight;
PlotModel.LegendBackground = OxyColor.FromAColor(200, OxyColors.White);
PlotModel.LegendBorder = OxyColors.Black;
PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Time (ms)" });
PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Data" });
var ScatterSeries1 = new ScatterSeries
{
MarkerSize = 3,
MarkerType = MarkerType.Diamond,
Title = "s1",
};
var ScatterSeries2 = new ScatterSeries
{
MarkerSize = 3,
MarkerType = MarkerType.Triangle,
Title = "s2",
};
var ScatterSeries3 = new ScatterSeries
{
MarkerSize = 3,
MarkerType = MarkerType.Square,
Title = "s3",
};
PlotModel.Series.Add(ScatterSeries1);
PlotModel.Series.Add(ScatterSeries2);
PlotModel.Series.Add(ScatterSeries3);
}
updateModel(int dataNum, List<int> dataList1, List<int> dataList2, List<int> dataList3)
{
var data1 = PlotModel.Series[0] as ScatterSeries; // 1st scatter
var data2 = PlotModel.Series[1] as ScatterSeries; // 2nd scatter
var data3 = PlotModel.Series[2] as ScatterSeries; // 3rd scatter
for (int i = 0; i < dataList.Length; i++)
{
data1.Points.Add(new ScatterPoint(i, dataList1[i]) { Value = i });
data2.Points.Add(new ScatterPoint(i, dataList2[i]) { Value = i });
data3.Points.Add(new ScatterPoint(i, dataList3[i]) { Value = i });
}
}
So lets say I press Data1 button, then the Data1 loads perfectly to the Oxyplot. However, if I then press another Data button, I see that the program is computing the new data and creating new points due to Debug statements but the plot doesn't actually refresh and update to the new Data set. What am I doing wrong?