终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

240 satır
15 KiB

  1. using LiveCharts.Definitions.Charts;
  2. using LiveCharts.Wpf;
  3. using OxyPlot.Axes;
  4. using OxyPlot;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using ThingsGateway.Foundation.Core;
  20. using BPASmartClient.Academy._50L;
  21. namespace BPASmartClient.Academy.View
  22. {
  23. /// <summary>
  24. /// DeviceChartView.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class DeviceChart50LView : UserControl
  27. {
  28. public DeviceChart50LView()
  29. {
  30. InitializeComponent();
  31. this.DataContext = DeviceChart50LViewModel.GetInstance;
  32. }
  33. public PlotModel plotModel { get; set; } = new PlotModel();
  34. private void DataView_CLick(object sender, MouseButtonEventArgs e)
  35. {
  36. ooo.Visibility = Visibility.Collapsed;
  37. double min = DateTimeAxis.ToDouble(System.DateTime.Now.AddMinutes(-10));
  38. double max = DateTimeAxis.ToDouble(System.DateTime.Now);
  39. double maxrange = max - min;
  40. CartesianChart liveCharts = sender as CartesianChart;
  41. switch (liveCharts.ToolTip)
  42. {
  43. case "温度曲线":
  44. {
  45. plotModel.Series.Clear();
  46. plotModel = new PlotModel() { Title = "温度曲线" };
  47. chartGrid.Visibility = Visibility.Visible;
  48. OxyPlot.Series.LineSeries templine = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  49. OxyPlot.Series.LineSeries templine_1 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "冷凝水罐温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  50. List<DataPoint> twValues = new List<DataPoint>();
  51. List<DataPoint> tvValues = new List<DataPoint>();
  52. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  53. {
  54. twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.Temperature));
  55. tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.CondensateWaterTemperature));
  56. });
  57. templine.Points.AddRange(twValues);
  58. templine_1.Points.AddRange(tvValues);
  59. //line_2.Points.AddRange(tmValues);
  60. if (!(plotModel.Axes.Count > 0))
  61. {
  62. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  63. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "温度/℃", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  64. }
  65. plotModel.Series.Add(templine);
  66. plotModel.Series.Add(templine_1);
  67. plotModel.InvalidatePlot(true);//重新加载曲线
  68. chartView.Model = plotModel;
  69. }
  70. break;
  71. case "压力曲线":
  72. {
  73. plotModel.Series.Clear();
  74. plotModel = new PlotModel() { Title = "反应釜蒸汽压力曲线" };
  75. chartGrid.Visibility = Visibility.Visible;
  76. OxyPlot.Series.LineSeries line = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜蒸汽压力", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  77. List<DataPoint> pressure = new List<DataPoint>();
  78. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  79. {
  80. pressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.SteamPressure));
  81. });
  82. line.Points.AddRange(pressure);
  83. if (!(plotModel.Axes.Count > 0))
  84. {
  85. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  86. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
  87. }
  88. plotModel.Series.Add(line);
  89. plotModel.InvalidatePlot(true);//重新加载曲线
  90. chartView.Model = plotModel;
  91. }
  92. break;
  93. case "比例阀开度曲线":
  94. {
  95. plotModel.Series.Clear();
  96. plotModel = new PlotModel() { Title = "比例阀开度曲线" };
  97. chartGrid.Visibility = Visibility.Visible;
  98. OxyPlot.Series.LineSeries line = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "蒸汽比例阀开度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  99. List<DataPoint> open = new List<DataPoint>();
  100. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  101. {
  102. open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ProportionalValveOpening));
  103. });
  104. line.Points.AddRange(open);
  105. if (!(plotModel.Axes.Count > 0))
  106. {
  107. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  108. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/%", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
  109. }
  110. plotModel.Series.Add(line);
  111. plotModel.InvalidatePlot(true);//重新加载曲线
  112. chartView.Model = plotModel;
  113. }
  114. break;
  115. case "流量曲线":
  116. {
  117. plotModel.Series.Clear();
  118. plotModel = new PlotModel() { Title = "流量曲线" };
  119. chartGrid.Visibility = Visibility.Visible;
  120. OxyPlot.Series.LineSeries templine = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜蒸汽流量", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  121. OxyPlot.Series.LineSeries templine_1 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "负压流量", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  122. List<DataPoint> twValues = new List<DataPoint>();
  123. List<DataPoint> tvValues = new List<DataPoint>();
  124. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  125. {
  126. twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.SteamFlowRate));
  127. tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.NegativePressureFlowRate));
  128. });
  129. templine.Points.AddRange(twValues);
  130. templine_1.Points.AddRange(tvValues);
  131. if (!(plotModel.Axes.Count > 0))
  132. {
  133. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  134. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "流量", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  135. }
  136. plotModel.Series.Add(templine);
  137. plotModel.Series.Add(templine_1);
  138. plotModel.InvalidatePlot(true);//重新加载曲线
  139. chartView.Model = plotModel;
  140. }
  141. break;
  142. case "重量曲线":
  143. {
  144. plotModel.Series.Clear();
  145. plotModel = new PlotModel() { Title = "重量曲线" };
  146. chartGrid.Visibility = Visibility.Visible;
  147. List<DataPoint> ww = new List<DataPoint>();
  148. List<DataPoint> ww1 = new List<DataPoint>();
  149. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  150. OxyPlot.Series.LineSeries line_6 = new OxyPlot.Series.LineSeries() { Title = "卤水罐重量", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  151. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  152. {
  153. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.WeighingWaterTankWeight));
  154. ww1.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.BrineTankWeight));
  155. });
  156. line_5.Points.AddRange(ww);
  157. line_6.Points.AddRange(ww1);
  158. if (!(plotModel.Axes.Count > 0))
  159. {
  160. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  161. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "重量/kg", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  162. }
  163. plotModel.Series.Add(line_5);
  164. plotModel.Series.Add(line_6);
  165. plotModel.InvalidatePlot(true);//重新加载曲线
  166. chartView.Model = plotModel;
  167. }
  168. break;
  169. case "湿度曲线":
  170. {
  171. plotModel.Series.Clear();
  172. plotModel = new PlotModel() { Title = "湿度曲线" };
  173. chartGrid.Visibility = Visibility.Visible;
  174. List<DataPoint> ww = new List<DataPoint>();
  175. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐湿度", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  176. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  177. {
  178. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.CondensateWaterHumidity));
  179. });
  180. line_5.Points.AddRange(ww);
  181. if (!(plotModel.Axes.Count > 0))
  182. {
  183. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  184. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "湿度", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  185. }
  186. plotModel.Series.Add(line_5);
  187. plotModel.InvalidatePlot(true);//重新加载曲线
  188. chartView.Model = plotModel;
  189. }
  190. break;
  191. case "反应釜角度曲线":
  192. {
  193. plotModel.Series.Clear();
  194. plotModel = new PlotModel() { Title = "反应釜角度曲线" };
  195. chartGrid.Visibility = Visibility.Visible;
  196. List<DataPoint> ww = new List<DataPoint>();
  197. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "反应釜角度", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  198. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  199. {
  200. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ReactEncoderValue));
  201. });
  202. line_5.Points.AddRange(ww);
  203. if (!(plotModel.Axes.Count > 0))
  204. {
  205. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  206. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "角度/°", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  207. }
  208. plotModel.Series.Add(line_5);
  209. plotModel.InvalidatePlot(true);//重新加载曲线
  210. chartView.Model = plotModel;
  211. }
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. private void Button_Click(object sender, RoutedEventArgs e)
  218. {
  219. chartGrid.Visibility = Visibility.Collapsed;
  220. ooo.Visibility = Visibility.Visible;
  221. plotModel.Axes.Clear();
  222. plotModel.Series.Clear();
  223. plotModel.InvalidatePlot(true);
  224. chartView.Model = plotModel;
  225. }
  226. }
  227. }