如何在 Oxyplot 中添加大量数据时自动平移

Una*_*gle 3 c# xamarin.ios 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);
Run Code Online (Sandbox Code Playgroud)

我已将 IsPanenabled 与系列系列相关联。但 id 并没有按预期进行。一次添加所有点有问题吗?我确信我做错了什么。我是否需要使用 Line 系列以外的其他系列?请指教 ..

Pet*_*ter 5

您应该同时设置DateTimeAxis.MaximumDateTimeAxis.Minimum。OxyPlot 尝试显示所有数据(如果是)NaN

如果Maximum和/或Minimum在绘图显示后发生更改,请进行以下调用以使更改生效。

DateTimeAxis.Zoom(DateTimeAxis.Minimum, DateTimeAxis.Maximum) 
Run Code Online (Sandbox Code Playgroud)

查看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; }
Run Code Online (Sandbox Code Playgroud)

源代码https://github.com/oxyplot/oxyplot/blob/master/Source/OxyPlot/Axes/Axis.cs