[英]How to PAN automatically while adding huge amount of data in Oxyplot
在XAMARIN iOS Oxyplot我想建立一些圖表來顯示電池趨勢。 它大約2000個數據點。 添加時,oxyplot嘗試將所有這些添加到可見區域。 然而,我希望它被淘汰和下降。
代碼如下
plotModel.Axes.Add (new LinearAxis {
Position = AxisPosition.Left,
MajorGridlineStyle = LineStyle.Dot,
Minimum = -2,
Maximum = 8,
AbsoluteMinimum = -2,
AbsoluteMaximum = 8,
MinorStep = 10,
MajorStep = 2
});
DateTimeAxis dtx = new DateTimeAxis {
Position = AxisPosition.Bottom,
MajorGridlineStyle = LineStyle.Dot,
AbsoluteMinimum = DateTimeAxis.ToDouble (batteryGraph.Min (v => v.LogTimeStamp)) - (0.5d / 60),
MajorStep = 5d,
StringFormat = "MM-dd-yy",
AbsoluteMaximum = DateTimeAxis.ToDouble (batteryGraph.Max (v => v.LogTimeStamp)) + (0.5d / 6),
Minimum = DateTimeAxis.ToDouble (batteryGraph.Min (v => v.LogTimeStamp)) - (0.5d / 60),
Maximum = DateTimeAxis.ToDouble (batteryGraph.Max (v => v.LogTimeStamp)) + (0.5d / 6)
};
plotModel.Axes.Add (dtx);
//For Low voltage alarm limit adding one line series
var limitSeries = new LineSeries {
Color = OxyColor.FromRgb (205, 92, 92),
};
var series = new LineSeries {
MarkerType = OxyPlot.MarkerType.Circle,
MarkerSize = 2,
MarkerStroke = OxyColor.FromRgb (0, 158, 214),
MarkerStrokeThickness = 2,
MarkerFill = OxyColors.White,
Color = OxyColor.FromRgb (0, 158, 214),
Smooth = true,
//DataFieldX2 = "X",
//ConstantY2 = 0,
IsPanEnabled=true
//Fill = OxyColor.FromArgb (30, 0, 158, 214),
};
plotModel.TouchStarted += (s, e) => {
//var point = series.InverseTransform(e.Position);
var point = series.GetNearestPoint (e.Position, true);
if (point == null && point.Item != null)
return;
var dataPoint = ((DataPoint)point.Item);
plotModel.Subtitle = "Date is= " + DateTimeAxis.ToDateTime (dataPoint.X) + " and Value = " + dataPoint.Y;
plotModel.InvalidatePlot (false);
e.Handled = false;
};
plotModel.InvalidatePlot (true);
//For Low voltage alarm limit adding one line series add some panning to left
limitSeries.Points.Add (DateTimeAxis.CreateDataPoint ((batteryGraph.Min (v => v.LogTimeStamp)).AddDays (-1), double.Parse (lowVoltAlarmLimit)));
foreach (var batteryInfo in batteryGraph) {
double batteryValue;
if (double.TryParse (batteryInfo.AuditItemData [0].Value.ToString (), out batteryValue))
;
series.Points.Add (DateTimeAxis.CreateDataPoint (batteryInfo.LogTimeStamp.ToLocalTime (), batteryValue));
//For Low voltage alarm limit adding one line series with same value
limitSeries.Points.Add (DateTimeAxis.CreateDataPoint (batteryInfo.LogTimeStamp.ToLocalTime (), double.Parse (lowVoltAlarmLimit)));
//series.Points2.Add (DateTimeAxis.CreateDataPoint (batteryInfo.LogTimeStamp.ToLocalTime (), -5));
}
plotModel.Series.Add (series);
////For Low voltage alarm limit adding one line series adding some panning to right
limitSeries.Points.Add (DateTimeAxis.CreateDataPoint ((batteryGraph.Max (v => v.LogTimeStamp)).AddDays (1), double.Parse (lowVoltAlarmLimit)));
//limitSeries.Points.Add (DateTimeAxis.CreateDataPoint (batteryGraph.Max (v => v.LogTimeStamp)) + 1d, double.Parse (lowVoltAlarmLimit)));
plotModel.Series.Add (limitSeries);
plotView.Model = plotModel;
graphView.AddSubview (plotView);
我已將IsPanenabled與line Series相關聯。 但是id並沒有像預期的那樣成功。 一次添加所有點是一個問題嗎? 我確信我做錯了什么。 我是否需要使用Line Series以外的其他系列? 請指教 ..
您應該同時設置DateTimeAxis.Maximum
和DateTimeAxis.Minimum
。 如果它們是NaN
OxyPlot會嘗試顯示所有數據。
如果在顯示繪圖后更改了Maximum
和/或Minimum
,請進行以下調用以使更改生效。
DateTimeAxis.Zoom(DateTimeAxis.Minimum, DateTimeAxis.Maximum)
看看OxyPlot的源代碼(下面的鏈接)注意以下屬性的評論:
/// <summary>
/// Gets or sets the actual maximum value of the axis.
/// </summary>
/// <remarks>If "ViewMaximum" is not NaN, this value will be defined by "ViewMaximum".
/// Otherwise, if "Maximum" is not NaN, this value will be defined by "Maximum".
/// Otherwise, this value will be defined by the maximum (+padding) of the data.</remarks>
public double ActualMaximum { get; protected set; }
/// <summary>
/// Gets or sets the maximum value of the axis. The default value is double.NaN.
/// </summary>
public double Maximum { get; set; }
/// <summary>
/// Gets or sets the 'padding' fraction of the maximum value. The default value is 0.01.
/// </summary>
/// <remarks> A value of 0.01 gives 1% more space on the maximum end of the axis. This property is not used if the "Maximum" property is set.</remarks>
public double MaximumPadding { get; set; }
/// <summary>
/// Gets or sets the current view's maximum. This value is used when the user zooms or pans.
/// </summary>
/// <value>The view maximum.</value>
protected double ViewMaximum { get; set; }
源代碼https://github.com/oxyplot/oxyplot/blob/master/Source/OxyPlot/Axes/Axis.cs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.