OxyPlot获取折线图选择区域的点的集合

关于OxyPlot的文档网上真的不全,官方文档也不祥不尽,所以没有办法就只有自己写了,不多说,直接上代码,拿来就可以直接用

使用OxyPlot控件,控件名plotView1

	private DateTimeAxis _dateAxis;//X轴
    private LinearAxis _valueAxis;//Y轴
    private PlotModel _myPlotModel;
    private Random rand = new Random();//用来生成随机数
	private void getStressData() {
        
        //定义model
        _myPlotModel = new PlotModel()
        {
            Title = "波形实时曲线",
            /*LegendTitle = "Legend",
            LegendOrientation = LegendOrientation.Horizontal,
            LegendPlacement = LegendPlacement.Inside,
            LegendPosition = LegendPosition.TopRight,
            LegendBackground = OxyColor.FromAColor(200, OxyColors.Beige),
            LegendBorder = OxyColors.Black*/
        };
        //X轴
        _dateAxis = new DateTimeAxis()
        {
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.Dot,
            IntervalLength = 80,
            IsZoomEnabled = true,
            Title= "长度(mm)",
            IsPanEnabled = true
        };
        _myPlotModel.Axes.Add(_dateAxis);

        //Y轴
        _valueAxis = new LinearAxis()
        {
            MajorGridlineStyle = LineStyle.Solid,
            MinorGridlineStyle = LineStyle.Dot,
            IntervalLength = 80,
            Angle = 60,
            IsZoomEnabled = true,
            IsPanEnabled = true,
            Title = "回拨强度",
            Maximum = 100,
            Minimum = -1
            
        };
        _myPlotModel.Axes.Add(_valueAxis);

      

        //添加两条曲线
        var series = new LineSeries()
        {
            Color = OxyColors.Green,
            StrokeThickness = 2,
            MarkerSize = 3,
            MarkerStroke = OxyColors.DarkGreen,
            MarkerType = MarkerType.Diamond,
            
           
        };
        




        _myPlotModel.Series.Add(series);
      
        

	
        plotView1.Model = _myPlotModel;

        Task.Factory.StartNew(() =>
        {
            while (true)
            {

                var date = DateTime.Now;
                _myPlotModel.Axes[0].Maximum = DateTimeAxis.ToDouble(date.AddSeconds(1));

                var lineSer = plotView1.Model.Series[0] as LineSeries;
                lineSer.Points.Add(new DataPoint(DateTimeAxis.ToDouble(date), rand.Next(100, 300) / 10.0));
                if (lineSer.Points.Count > 1000)
                {
                    lineSer.Points.RemoveAt(0);
                }

               

                

                _myPlotModel.InvalidatePlot(true);

                Thread.Sleep(1000);
            }
        });

    }

这里是获取折线图选择区域的点的集合

	private TrackerHitResult srartSeries;//选择点区间时起始点

    private TrackerHitResult endSeries;//选择点区间时结束点

    double seriesStartX;//选择点区间时起始横坐标
    double seriesStartY;//选择点区间时起始纵坐标

    List<DataPoint> benchmark;//选择点区间包含的所有点


    bool seriesFlag = false;


    private void plotView1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Middle)
        {
            
            seriesStartX = e.X;
            seriesStartY = e.Y;
            
            seriesFlag = true;
            

        }
    }

    private void plotView1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Middle&&seriesFlag)
        {
           
            if (seriesStartX!=e.X) {

                var startCoordinates = new ScreenPoint(seriesStartX, seriesStartY);
                var endCoordinates = new ScreenPoint(e.X, e.Y);

				
                srartSeries = (_myPlotModel.Series[0] as LineSeries).GetNearestPoint(startCoordinates, false);


                var endSeries = (_myPlotModel.Series[0] as LineSeries).GetNearestPoint(endCoordinates, false);
				
                benchmark=(_myPlotModel.Series[0] as LineSeries).Points.GetRange((int)srartSeries.Index,(int)(endSeries.Index- srartSeries.Index+1));


            }
            
           

        }

    }

至于DataPoint是什么,就是OxyPlot的点的对象,如果还不知道,就打断点看吧。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值