在遇到同样的问题后,似乎唯一可行的解决方案(至少在我看来)如下:
PlotView.InvalidatePlot(true)
这样做,在更新一个或多个Series 后,请刷新您的PlotView。
刷新率取决于您的系列的更新频率或更新率。
这是一个代码 sn-p(在 Xamarin Android 上,但应该可以正常工作):
PlotView resultsChart = FindViewById<PlotView>(Resource.Id.resultsChart);
PlotModel plotModel = new PlotModel
{
// set here main properties such as the legend, the title, etc. example :
Title = "My Awesome Real-Time Updated Chart",
TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinPlotArea,
LegendTitle = "I am a Legend",
LegendOrientation = LegendOrientation.Horizontal,
LegendPlacement = LegendPlacement.Inside,
LegendPosition = LegendPosition.TopRight
// there are many other properties you can set here
}
// now let's define X and Y axis for the plot model
LinearAxis xAxis = new LinearAxis();
xAxis.Position = AxisPosition.Bottom;
xAxis.Title = "Time (hours)";
LinearAxis yAxis = new LinearAxis();
yAxis.Position = AxisPosition.Left;
yAxis.Title = "Values";
plotModel.Axes.Add(xAxis);
plotModel.Axes.Add(yAxis);
// Finally let's define a LineSerie
LineSeries lineSerie = new LineSeries
{
StrokeThickness = 2,
CanTrackerInterpolatePoints = false,
Title = "Value",
Smooth = false
};
plotModel.Series.Add(lineSerie);
resultsChart.Model = plotModel;
现在,当您需要将DataPoints 添加到您的LineSerie 并相应地自动更新PlotView 时,只需执行以下操作:
resultsChart.InvalidatePlot(true);
这样做会自动刷新您的PlotView。
附带说明,PlotView 也会在发生触摸、捏合缩放或任何类型的 UI 相关事件等事件时更新。
我希望我能帮上忙。我为此困扰了很长时间。