其他分享
首页 > 其他分享> > OxyPlot的动态曲线图表

OxyPlot的动态曲线图表

作者:互联网

前台

  <oxy:PlotView Model="{Binding DynamicCurve}" /> 

 Model中

public PlotModel DynamicCurve{ get; set; }

public void PlotViewModel()
        {
            DynamicCurve = new PlotModel();
            //定义x轴
            OxyPlot.Axes.LinearAxis bottomAxis = new OxyPlot.Axes.LinearAxis()
            {
                Position = AxisPosition.Bottom,
                Minimum = 0,
                Maximum = 10,

                //IsAxisVisible = false,//X轴不显示
                //Title = "X轴",//显示标题内容
                //TitlePosition = 1,//显示标题位置
                //TitleColor = OxyColor.Parse("#d3d3d3"),//显示标题位置
                IsZoomEnabled = false,//坐标轴缩放关闭
                IsPanEnabled = false,//图表缩放功能关闭
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
            };
            //定义y轴
            OxyPlot.Axes.LinearAxis leftAxis = new OxyPlot.Axes.LinearAxis()
            {
                Position = AxisPosition.Left,
                Minimum = -5,
                Maximum = 5,
                //Title = "Y轴",//显示标题内容
                //TitlePosition = 1,//显示标题位置
                //TitleColor = OxyColor.Parse("#d3d3d3"),//显示标题位置
                IsZoomEnabled = false,//坐标轴缩放关闭
                IsPanEnabled = false,//图表缩放功能关闭

                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
            };
           

            DynamicCurve.Axes.Add(bottomAxis);
            DynamicCurve.Axes.Add(leftAxis);

            var rd = new Random();
            ////添加曲线
            var series = new LineSeries()
            {
                Color = OxyColors.Green,
                StrokeThickness = 2,
                MarkerSize = 3,
                MarkerStroke = OxyColors.DarkGreen,
                MarkerType = MarkerType.Diamond,
                Title = "Temp"

            };
            DynamicCurve.Series.Add(series);
            int i = 0;
            Task.Factory.StartNew(() =>
            {
                while (true)
                { 
                    DynamicCurve.Axes[0].Maximum = 5+i;
                    series.Points.Add(new DataPoint(i, rand.Next(-5, 5)));
                    if (series.Points.Count > 100)
                    {
                        series.Points.RemoveAt(0);
                    }

                    DynamicCurve.InvalidatePlot(true);

                    Thread.Sleep(1000);
                    i++;
                }
            });


        }

标签:OxyPlot,Axes,false,series,曲线,DynamicCurve,图表,new
来源: https://www.cnblogs.com/lzwei/p/14538868.html