WPF_OXY绘图

复制代码
 plotModel = new PlotModel()
            {
                Title = "数据统计",
                LegendTitle = "Max:红色,Min:黄色",
                LegendOrientation = LegendOrientation.Horizontal,
                LegendPlacement = LegendPlacement.Inside,
                LegendPosition = LegendPosition.TopRight,
                LegendBackground = OxyColor.FromAColor(200, OxyColors.Beige),
                LegendBorder = OxyColors.Black,
                DefaultFont = "微软雅黑",
            };

            #region X,Y轴


            //X轴
            var _dateAxis = new DateTimeAxis()
            {
                MajorGridlineStyle = LineStyle.Solid,
                MinorGridlineStyle = LineStyle.Dot,
                IntervalLength = 80,
                IsZoomEnabled = false,
                IsPanEnabled = false,
                StringFormat = "M/d HH:mm:ss",
                Title = "时间"
            };
            plotModel.Axes.Add(_dateAxis);

            //Y轴
            var _valueAxis = new LinearAxis()
            {
                Title = "数值",
                Maximum = usl + usl / 4,
                Minimum = lsl - lsl / 3,
                MajorGridlineStyle = LineStyle.Solid,//主刻度设置格网
                MinorGridlineStyle = LineStyle.Dot,//子刻度设置格网样式
                IntervalLength = 80,
                Angle = 60,
                IsZoomEnabled = true,//坐标轴缩放
                IsPanEnabled = true,//图表缩放功能 
                Position = AxisPosition.Left,
            };
            plotModel.Axes.Add(_valueAxis);

            #endregion

            #region 线条

            //动态线条
            var lineSerial = new LineSeries()
            {
                Title = SvidSelected.ParaName,//eqpParam name
                Color = OxyColors.Black,
                Smooth = true,
                MarkerType = MarkerType.Circle,
                StrokeThickness = 0,
                MarkerSize = 1,
                MarkerStroke = OxyColors.BlueViolet,
            };
            plotModel.Series.Add(lineSerial);

            Task.Factory.StartNew(() =>
               {
                   for (int i = 0; i < resData.Count; i++)
                   {
                       lineSerial.Points.Add(DateTimeAxis.CreateDataPoint(resData[i].occurenceTime, resData[i].val));
                       plotModel.InvalidatePlot(true); //每秒刷新一次视图 
                       //Thread.Sleep(200);
                   }
                   sw.Stop();
                   TotalDate = "总渲染时间(毫秒):" + sw.ElapsedMilliseconds;//sw.ElapsedTicks / (decimal)Stopwatch.Frequency;
               });

            #endregion

            #region 上限,下限,中线

            //添加标注线
            var lineMaxAnnotation = new LineAnnotation()
            {//上限
                Type = LineAnnotationType.Horizontal,
                Y = usl,
                Text = "上限:" + usl,
                Color = OxyColors.Red,
                LineStyle = LineStyle.DashDashDot,
                StrokeThickness = 2
            };
            plotModel.Annotations.Add(lineMaxAnnotation);

            var lineMinAnnotation = new LineAnnotation()
            {//下限
                Type = LineAnnotationType.Horizontal,
                Color = OxyColors.Blue,
                LineStyle = LineStyle.Dash,
                StrokeThickness = 2,
                Y = lsl,
                Text = "下限:" + lsl
            };
            plotModel.Annotations.Add(lineMinAnnotation);

            var lineMean = new LineAnnotation()
            {//平均
                Type = LineAnnotationType.Horizontal,
                Color = OxyColors.Green,
                LineStyle = LineStyle.LongDash,
                StrokeThickness = 2,
                Y = mean,
                Text = "平均:" + mean
            };
            plotModel.Annotations.Add(lineMean);

            #endregion

            #region 最大值,最小值

            var min = new ScatterSeries();
            var maxDataPoint = DateTimeAxis.CreateDataPoint(maxPoint.occurenceTime, maxPoint.val);
            min.Points.Add(new ScatterPoint(maxDataPoint.X, maxDataPoint.Y, 15));
            min.MarkerFill = OxyColor.FromAColor(20, OxyColors.Red);
            min.MarkerType = MarkerType.Circle;
            plotModel.Series.Add(min);

            var max = new ScatterSeries();
            var minDataPoint = DateTimeAxis.CreateDataPoint(minPoint.occurenceTime, minPoint.val);
            max.Points.Add(new ScatterPoint(minDataPoint.X, minDataPoint.Y, 15));
            max.MarkerFill = OxyColor.FromAColor(20, OxyColors.Yellow);
            max.MarkerType = MarkerType.Circle;
            plotModel.Series.Add(max);

            #endregion
复制代码

 

posted @   彪悍的代码不需要注释  阅读(447)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
39
0
点击右上角即可分享
微信分享提示