【问题标题】:How to PAN automatically while adding huge amount of data in Oxyplot如何在 Oxyplot 中添加大量数据时自动平移
【发布时间】:2016-05-06 06:05:15
【问题描述】:

在 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 与系列系列相关联。但是 id 没有按预期工作。一次添加所有点是否有问题?我确定我做错了什么。我需要使用 Line 系列以外的其他系列吗?请指教..

【问题讨论】:

    标签: c# xamarin.ios oxyplot


    【解决方案1】:

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

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

    DateTimeAxis.Zoom(DateTimeAxis.Minimum, DateTimeAxis.Maximum) 
    

    看看OxyPlot的源代码(链接如下)注意以下属性的cmets:

        /// <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

    【讨论】:

    • 非常感谢您的及时回复和参考。我也试过最大/最小。而我的代码只显示 "maximum" 。很抱歉在我的复制粘贴操作期间错过了“最小”属性。仍然没有令人满意的结果。
    • @Attu 请更新您设置最小值的方式,以便人们可以提供帮助。
    • 抱歉耽搁了,不在城里。修改了特定部分(dtx 属性)。如果您需要我的任何意见,请告诉我。谢谢
    • @Attu 我不确定batteryGraph 的定义是什么,但似乎 x-axis(dtx) 的 Minimum 属性设置为包含最小数据?尝试将其设置为相同的最大值减去某个范围,看看是否有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 1970-01-01
    • 2017-11-13
    • 1970-01-01
    相关资源
    最近更新 更多