在对同样的问题提出同样的问题之后,似乎唯一可行的解决方案(至少在我看来)如下:
PlotView.InvalidatePlot(true)
这样做,在更新一个或多个之后Series
刷新你的PlotView
.
刷新率取决于您的系列更新的频率或频率。
这是一个代码片段(在 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 相关事件。
我希望我能帮上忙。很长一段时间以来,我都遇到了麻烦。