当有人单击按钮时,我试图更新10次图。
单击按钮时,图将按预期更新,但仅更新一次。我似乎只使用int迭代器获得循环中的最后一个绘图更新。
我尝试清除绘图模型系列,并按照oxyplot github上的建议使用InvalidatePlot(true)方法。
有什么想法吗?
public class MainViewModel
{
public PlotModel PlotModel { get; set;}
public Random random = new Random();
public MainViewModel()
{
this.PlotModel = new PlotModel();
var xAxis = new LinearAxis
{ Title = "X", Position = AxisPosition.Bottom, };
PlotModel.Axes.Add(xAxis);
var yAxis = new LinearAxis
{ Title = "Y", Position = AxisPosition.Left };
PlotModel.Axes.Add(yAxis);
var series = new LineSeries();
UpdatePoints(series);
PlotModel.Series.Add(series);
}
public void ButtonClicked()
{
for (int iter = 0; iter < 10; iter++)
{
UpdatePlot();
PlotModel.InvalidatePlot(true);
}
}
public void UpdatePlot()
{
var currentSeries = (LineSeries)PlotModel.Series[0];
currentSeries.Points.Clear();
UpdatePoints(currentSeries);
}
public void UpdatePoints(LineSeries series)
{
var dataPoints = new List<DataPoint>();
for (int i = 0; i < 1000; i++)
{
series.Points.Add(new DataPoint(random.NextDouble(), random.NextDouble()));
}
}
}