博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF——OXY绘图
阅读量:4639 次
发布时间:2019-06-09

本文共 7858 字,大约阅读时间需要 26 分钟。

private PlotModel _plotModel;        public PlotModel plotModel        {            get { return _plotModel; }            set            {                _plotModel = value;                RaisePropertyChanged("plotModel");            }        }        public void LoadChart()        {            BeginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");            Stopwatch sw = new Stopwatch();            sw.Start();            var resData = JsonConvert.DeserializeObject
>(WcfConnector.GetInstance().QuerySroodRawData(QueryEqpId, RouteSelected.RunId, SvidSelected.ParaName)); var orderList = resData.OrderByDescending(m => m.val); var maxPoint = orderList.FirstOrDefault(); var minPoint = orderList.LastOrDefault(); var mean = 107.5; 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); //var startDate = DateTime.Now.AddDays(-10); //var endDate = DateTime.Now; //var minValue = DateTimeAxis.ToDouble(startDate); //var maxValue = DateTimeAxis.ToDouble(endDate); //Y轴 var _valueAxis = new LinearAxis() { Title = "数值", Maximum = maxPoint.val + maxPoint.val / 4, Minimum = minPoint.val - minPoint.val / 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 = 1, MarkerSize = 2, 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); } }); //plotModel.InvalidatePlot(false); #endregion #region 上下限 //添加标注线 var lineMaxAnnotation = new LineAnnotation() {
//上限 Type = LineAnnotationType.Horizontal, Y = maxPoint.val, Text = "上限:" + maxPoint.val, 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 = minPoint.val, Text = "下限:" + minPoint.val }; 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(120, 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(120, OxyColors.Yellow); max.MarkerType = MarkerType.Circle; plotModel.Series.Add(max); #endregion #region 线条2 ////动态线条 //var lineSerial3 = new LineSeries() //{ // Title = "CF3", // Color = OxyColors.Blue, // Smooth = true, // MarkerType = MarkerType.Circle, // StrokeThickness = 2, // MarkerSize = 3, // MarkerStroke = OxyColors.BlueViolet //}; //plotModel.Series.Add(lineSerial3); //var count = 50; //var rd3 = new Random(); //Task.Factory.StartNew(() => //{ // var list = new List
(); // while (count > 0) // { // var point = DateTimeAxis.CreateDataPoint(DateTime.Now, rd3.Next(15, 60)); // list.Add(point); // lineSerial3.Points.Add(point); // //if (lineSerial3.Points.Count > 1000) // //{ // // lineSerial3.Points.RemoveAt(0); // //} // plotModel.InvalidatePlot(true); //每秒刷新一次视图 // Thread.Sleep(500); // count--; // } // if (list.Count > 0) // { // var list1 = list.OrderByDescending(m => m.Y); // var maxPoint = list1.FirstOrDefault(); // var minPoint = list1.LastOrDefault(); // var min = new ScatterSeries(); // min.Points.Add(new ScatterPoint(maxPoint.X, maxPoint.Y, 15)); // min.MarkerFill = OxyColor.FromAColor(120, OxyColors.Red); // min.MarkerType = MarkerType.Circle; // plotModel.Series.Add(min); // var max = new ScatterSeries(); // max.Points.Add(new ScatterPoint(minPoint.X, minPoint.Y, 15)); // max.MarkerFill = OxyColor.FromAColor(120, OxyColors.Yellow); // max.MarkerType = MarkerType.Circle; // plotModel.Series.Add(max); // } //}); #endregion EndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"); sw.Stop(); TotalDate = sw.ElapsedTicks / (decimal)Stopwatch.Frequency; }

 

转载于:https://www.cnblogs.com/ingstyle/p/11205191.html

你可能感兴趣的文章
关于用户管理的思考
查看>>
小试牛刀【龙哥翻译】
查看>>
利用python重启路由器
查看>>
oracle 闪回操作(flashback)
查看>>
简单的jsonp实现跨域原理
查看>>
setvlet基础知识
查看>>
Css动画形式弹出遮罩层,内容区上下左右居中于不定宽高的容器中
查看>>
延迟加载、分页显示等功能的增加
查看>>
在Objective-C中浅谈面向对象
查看>>
解决vs2013不能添加控制器的步骤
查看>>
JAVA基础-数组
查看>>
【区间DP】能量项链
查看>>
trove 开发者阅读翻译
查看>>
WinForm 弹框确认后执行
查看>>
CRM Home Grid StyleSet
查看>>
遍历checktree 选中的节点,就是前面打勾的
查看>>
基于TCP/IP的长连接和短连接
查看>>
SharePoint Framework解决方案管理参考(二)
查看>>
使用PowerShell在Windows 10中创建本地用户帐户
查看>>
让服务器可以下载apk和ipa文件
查看>>