1. private PlotModel _plotModel;
  2. public PlotModel plotModel
  3. {
  4. get { return _plotModel; }
  5. set
  6. {
  7. _plotModel = value;
  8. RaisePropertyChanged("plotModel");
  9. }
  10. }
  11.  
  12. public void LoadChart()
  13. {
  14. BeginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
  15.  
  16. Stopwatch sw = new Stopwatch();
  17. sw.Start();
  18.  
  19. var resData = JsonConvert.DeserializeObject<List<ResultModel>>(WcfConnector.GetInstance().QuerySroodRawData(QueryEqpId, RouteSelected.RunId, SvidSelected.ParaName));
  20.  
  21. var orderList = resData.OrderByDescending(m => m.val);
  22. var maxPoint = orderList.FirstOrDefault();
  23. var minPoint = orderList.LastOrDefault();
  24. var mean = 107.5;
  25.  
  26. plotModel = new PlotModel()
  27. {
  28. Title = "数据统计",
  29. LegendTitle = "Max:红色,Min:黄色",
  30. LegendOrientation = LegendOrientation.Horizontal,
  31. LegendPlacement = LegendPlacement.Inside,
  32. LegendPosition = LegendPosition.TopRight,
  33. LegendBackground = OxyColor.FromAColor(, OxyColors.Beige),
  34. LegendBorder = OxyColors.Black,
  35. DefaultFont = "微软雅黑",
  36. };
  37.  
  38. #region X,Y轴
  39.  
  40. //X轴
  41. var _dateAxis = new DateTimeAxis()
  42. {
  43. MajorGridlineStyle = LineStyle.Solid,
  44. MinorGridlineStyle = LineStyle.Dot,
  45. IntervalLength = ,
  46. IsZoomEnabled = false,
  47. IsPanEnabled = false,
  48. StringFormat = "M/d HH:mm:ss",
  49. Title = "时间"
  50. };
  51. plotModel.Axes.Add(_dateAxis);
  52.  
  53. //var startDate = DateTime.Now.AddDays(-10);
  54. //var endDate = DateTime.Now;
  55. //var minValue = DateTimeAxis.ToDouble(startDate);
  56. //var maxValue = DateTimeAxis.ToDouble(endDate);
  57.  
  58. //Y轴
  59. var _valueAxis = new LinearAxis()
  60. {
  61. Title = "数值",
  62. Maximum = maxPoint.val + maxPoint.val / ,
  63. Minimum = minPoint.val - minPoint.val / ,
  64. MajorGridlineStyle = LineStyle.Solid,//主刻度设置格网
  65. MinorGridlineStyle = LineStyle.Dot,//子刻度设置格网样式
  66. IntervalLength = ,
  67. Angle = ,
  68. IsZoomEnabled = true,//坐标轴缩放
  69. IsPanEnabled = true,//图表缩放功能
  70. Position = AxisPosition.Left,
  71. };
  72. plotModel.Axes.Add(_valueAxis);
  73.  
  74. #endregion
  75.  
  76. #region 线条
  77.  
  78. //动态线条
  79. var lineSerial = new LineSeries()
  80. {
  81. Title = SvidSelected.ParaName,//eqpParam name
  82. Color = OxyColors.Black,
  83. Smooth = true,
  84. MarkerType = MarkerType.Circle,
  85. StrokeThickness = ,
  86. MarkerSize = ,
  87. MarkerStroke = OxyColors.BlueViolet,
  88. };
  89. plotModel.Series.Add(lineSerial);
  90.  
  91. Task.Factory.StartNew(() =>
  92. {
  93. for (int i = ; i < resData.Count; i++)
  94. {
  95. lineSerial.Points.Add(DateTimeAxis.CreateDataPoint(resData[i].occurenceTime, resData[i].val));
  96. plotModel.InvalidatePlot(true); //每秒刷新一次视图
  97. Thread.Sleep();
  98. }
  99. });
  100.  
  101. //plotModel.InvalidatePlot(false);
  102.  
  103. #endregion
  104.  
  105. #region 上下限
  106.  
  107. //添加标注线
  108. var lineMaxAnnotation = new LineAnnotation()
  109. {//上限
  110. Type = LineAnnotationType.Horizontal,
  111. Y = maxPoint.val,
  112. Text = "上限:" + maxPoint.val,
  113. Color = OxyColors.Red,
  114. LineStyle = LineStyle.DashDashDot,
  115. StrokeThickness =
  116. };
  117. plotModel.Annotations.Add(lineMaxAnnotation);
  118.  
  119. var lineMinAnnotation = new LineAnnotation()
  120. {//下限
  121. Type = LineAnnotationType.Horizontal,
  122. Color = OxyColors.Blue,
  123. LineStyle = LineStyle.Dash,
  124. StrokeThickness = ,
  125. Y = minPoint.val,
  126. Text = "下限:" + minPoint.val
  127. };
  128. plotModel.Annotations.Add(lineMinAnnotation);
  129.  
  130. var lineMean = new LineAnnotation()
  131. {//平均
  132. Type = LineAnnotationType.Horizontal,
  133. Color = OxyColors.Green,
  134. LineStyle = LineStyle.LongDash,
  135. StrokeThickness = ,
  136. Y = mean,
  137. Text = "平均:" + mean
  138. };
  139. plotModel.Annotations.Add(lineMean);
  140.  
  141. #endregion
  142.  
  143. #region 最大值,最小值
  144.  
  145. var min = new ScatterSeries();
  146. var MaxDataPoint = DateTimeAxis.CreateDataPoint(maxPoint.occurenceTime, maxPoint.val);
  147. min.Points.Add(new ScatterPoint(MaxDataPoint.X, MaxDataPoint.Y, ));
  148. min.MarkerFill = OxyColor.FromAColor(, OxyColors.Red);
  149. min.MarkerType = MarkerType.Circle;
  150. plotModel.Series.Add(min);
  151.  
  152. var max = new ScatterSeries();
  153. var minDataPoint = DateTimeAxis.CreateDataPoint(minPoint.occurenceTime, minPoint.val);
  154. max.Points.Add(new ScatterPoint(minDataPoint.X, minDataPoint.Y, ));
  155. max.MarkerFill = OxyColor.FromAColor(, OxyColors.Yellow);
  156. max.MarkerType = MarkerType.Circle;
  157. plotModel.Series.Add(max);
  158.  
  159. #endregion
  160.  
  161. #region 线条2
  162.  
  163. ////动态线条
  164. //var lineSerial3 = new LineSeries()
  165. //{
  166. // Title = "CF3",
  167. // Color = OxyColors.Blue,
  168. // Smooth = true,
  169. // MarkerType = MarkerType.Circle,
  170. // StrokeThickness = 2,
  171. // MarkerSize = 3,
  172. // MarkerStroke = OxyColors.BlueViolet
  173. //};
  174. //plotModel.Series.Add(lineSerial3);
  175.  
  176. //var count = 50;
  177.  
  178. //var rd3 = new Random();
  179. //Task.Factory.StartNew(() =>
  180. //{
  181. // var list = new List<DataPoint>();
  182.  
  183. // while (count > 0)
  184. // {
  185. // var point = DateTimeAxis.CreateDataPoint(DateTime.Now, rd3.Next(15, 60));
  186. // list.Add(point);
  187. // lineSerial3.Points.Add(point);
  188. // //if (lineSerial3.Points.Count > 1000)
  189. // //{
  190. // // lineSerial3.Points.RemoveAt(0);
  191. // //}
  192. // plotModel.InvalidatePlot(true); //每秒刷新一次视图
  193. // Thread.Sleep(500);
  194. // count--;
  195. // }
  196.  
  197. // if (list.Count > 0)
  198. // {
  199. // var list1 = list.OrderByDescending(m => m.Y);
  200. // var maxPoint = list1.FirstOrDefault();
  201. // var minPoint = list1.LastOrDefault();
  202.  
  203. // var min = new ScatterSeries();
  204. // min.Points.Add(new ScatterPoint(maxPoint.X, maxPoint.Y, 15));
  205. // min.MarkerFill = OxyColor.FromAColor(120, OxyColors.Red);
  206. // min.MarkerType = MarkerType.Circle;
  207. // plotModel.Series.Add(min);
  208.  
  209. // var max = new ScatterSeries();
  210. // max.Points.Add(new ScatterPoint(minPoint.X, minPoint.Y, 15));
  211. // max.MarkerFill = OxyColor.FromAColor(120, OxyColors.Yellow);
  212. // max.MarkerType = MarkerType.Circle;
  213. // plotModel.Series.Add(max);
  214.  
  215. // }
  216. //});
  217.  
  218. #endregion
  219.  
  220. EndDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
  221. sw.Stop();
  222. TotalDate = sw.ElapsedTicks / (decimal)Stopwatch.Frequency;
  223. }

WPF——OXY绘图的更多相关文章

  1. WPF——OXY绘图_old

    plotModel = new PlotModel() { Title = "数据统计", LegendTitle = "Max:红色,Min:黄色", Leg ...

  2. WPF 在绘图控件(Shape)中添加文字 [2018.7.15]

    原文:WPF 在绘图控件(Shape)中添加文字 [2018.7.15] Q:使用Shape的子类Ellipse画一个圆,如何在圆中添加文字? A:Shape类中不包含Text属性.可使用Shape类 ...

  3. WPF特效-绘图

    原文:WPF特效-绘图                  WPF玩起来还是挺炫酷的.我实现的效果:不同色块交叉,交叉部分颜色叠加显示.(叠加部分暂时用随机颜色代替).单独色块点击弹出以色块颜色为主的附 ...

  4. WPF 实时绘图的逻辑

    实时绘图实际上是两个线程.外部线程直接用thread,只有到绘图那个逻辑才用绘图控件的mycanvas2.Dispatcher.Invoke. 或者说,INVOKE并不是开线程,只是一个绘图的委托而已 ...

  5. WPF中绘图(含调用GDI+)

    private void DrawStuff() { // //if (buffer == null) //{ // buffer = new RenderTargetBitmap((int)Back ...

  6. WPF学习(11)2D绘图

    本篇我们来学习WPF的绘图,在2D绘图中主要有这么几个重要的类:Drawing.Visual和Shape,顺便讲下Brush和BitmapEffect. 1 2D绘图 1.1Drawing类 Draw ...

  7. 《Programming WPF》翻译 第7章 1.图形基础

    原文:<Programming WPF>翻译 第7章 1.图形基础 WPF使得在你的应用程序中使用图形很容易,以及更容易开发你的显卡的能力.这有很多图形构架的方面来达到这个目标.其中最重要 ...

  8. WPF绘制深度不同颜色的3D模型填充图和线框图

    原文:WPF绘制深度不同颜色的3D模型填充图和线框图 在机械测量过程中,测量的数据需要进行软件处理.通常测量一个零件之后,需要重建零件的3D模型,便于观察测量结果是否与所测工件一致. 重建的3D模型需 ...

  9. WPF特效-绘制实时2D激光雷达图

    原文:WPF特效-绘制实时2D激光雷达图 接前两篇: https://blog.csdn.net/u013224722/article/details/80738619 https://blog.cs ...

随机推荐

  1. N(C)O(S)I(P)P 2019 退役记

    N(C)O(S)I(P)P 2019 退役记 day-4 今天下午老师突然咕了,于是一下午欢乐时光 今天上午考试T3线段树维护个区间加,区间乘 一遍过编译,一遍过样例(第一次,俺比较弱(虽然也发现和暴 ...

  2. easyui datagrid Column Group 列组、 复杂表头 嵌套表头 组合表头 (转载)

    核心: rowspan:2   //占两行 colspan:3    //占三列 所有的colspan下的二级列表头,统一放在一个数组里. 文章一: 转载来源:https://blog.csdn.ne ...

  3. 【漏洞复现】Apache Solr via Velocity template远程代码执行

    0x01 概述 Solr简介 Apache Solr 是一个开源的企业级搜索服务器.Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现.Apache Solr ...

  4. 服务器架构前面加了防火墙,Nginx如何获取客户端真实ip???

    在大部分实际业务场景中,网站访问请求并不是简单地从用户(访问者)的浏览器直达网站的源站服务器,中间可能经过所部署的CDN.高防IP.WAF等代理服务器.例如,网站可能采用这样的部署架构:用户 > ...

  5. Java httpclent请求httpclentUtils工具类

    第一种写法: import java.io.IOException; import java.io.InterruptedIOException; import java.io.Unsupported ...

  6. Fedora 29 安装 GitBook 教程

    Fedora 29 安装 GitBook 教程 本文原始地址:https://sitoi.cn/posts/53731.html 安装 nvm 安装 nvm curl -o- https://raw. ...

  7. Unexpected EOF in archive 或者 rmtlseek not stopped at a record boundary

    多半都是文件在传输.复制的时候,发生了损坏: 尽量cp不要用mv 其次,注意文件的大小:

  8. PAT 乙级 1040.有几个PAT C++/Java

    题目来源 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位( ...

  9. 关于background-image设置背景图片

    每天进步一小步,一年进步一大步. 本篇主要介绍背景图片设置,平铺,x y方向上的平铺,是否重复显示no repeat  显示的初始位置 background-image:url(images/inde ...

  10. Css背景设置 、

    每天进步一小步,一年进步一大步. 第一次发博客园文章,主要记录自己学习的一个过程. CSS3 背景 CSS3 包含多个新的背景属性,它们提供了对背景更强大的控制. background-size ba ...