终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

245 lines
16 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. OxyPlot.Series.LineSeries line2 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜压力", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  78. List<DataPoint> steamPressure = new List<DataPoint>();
  79. List<DataPoint> reactPressure = new List<DataPoint>();
  80. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  81. {
  82. steamPressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.SteamPressure));
  83. reactPressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ReactPressure));
  84. });
  85. line.Points.AddRange(steamPressure);
  86. line2.Points.AddRange(reactPressure);
  87. if (!(plotModel.Axes.Count > 0))
  88. {
  89. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  90. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
  91. }
  92. plotModel.Series.Add(line);
  93. plotModel.Series.Add(line2);
  94. plotModel.InvalidatePlot(true);//重新加载曲线
  95. chartView.Model = plotModel;
  96. }
  97. break;
  98. case "比例阀开度曲线":
  99. {
  100. plotModel.Series.Clear();
  101. plotModel = new PlotModel() { Title = "比例阀开度曲线" };
  102. chartGrid.Visibility = Visibility.Visible;
  103. 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 };
  104. List<DataPoint> open = new List<DataPoint>();
  105. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  106. {
  107. open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ProportionalValveOpening));
  108. });
  109. line.Points.AddRange(open);
  110. if (!(plotModel.Axes.Count > 0))
  111. {
  112. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  113. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/%", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
  114. }
  115. plotModel.Series.Add(line);
  116. plotModel.InvalidatePlot(true);//重新加载曲线
  117. chartView.Model = plotModel;
  118. }
  119. break;
  120. case "流量曲线":
  121. {
  122. plotModel.Series.Clear();
  123. plotModel = new PlotModel() { Title = "流量曲线" };
  124. chartGrid.Visibility = Visibility.Visible;
  125. 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 };
  126. 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 };
  127. List<DataPoint> twValues = new List<DataPoint>();
  128. List<DataPoint> tvValues = new List<DataPoint>();
  129. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  130. {
  131. twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.SteamFlowRate));
  132. tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.NegativePressureFlowRate));
  133. });
  134. templine.Points.AddRange(twValues);
  135. templine_1.Points.AddRange(tvValues);
  136. if (!(plotModel.Axes.Count > 0))
  137. {
  138. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  139. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "流量", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  140. }
  141. plotModel.Series.Add(templine);
  142. plotModel.Series.Add(templine_1);
  143. plotModel.InvalidatePlot(true);//重新加载曲线
  144. chartView.Model = plotModel;
  145. }
  146. break;
  147. case "重量曲线":
  148. {
  149. plotModel.Series.Clear();
  150. plotModel = new PlotModel() { Title = "重量曲线" };
  151. chartGrid.Visibility = Visibility.Visible;
  152. List<DataPoint> ww = new List<DataPoint>();
  153. List<DataPoint> ww1 = new List<DataPoint>();
  154. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  155. OxyPlot.Series.LineSeries line_6 = new OxyPlot.Series.LineSeries() { Title = "卤水罐重量", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  156. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  157. {
  158. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.WeighingWaterTankWeight));
  159. ww1.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.BrineTankWeight));
  160. });
  161. line_5.Points.AddRange(ww);
  162. line_6.Points.AddRange(ww1);
  163. if (!(plotModel.Axes.Count > 0))
  164. {
  165. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  166. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "重量/kg", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  167. }
  168. plotModel.Series.Add(line_5);
  169. plotModel.Series.Add(line_6);
  170. plotModel.InvalidatePlot(true);//重新加载曲线
  171. chartView.Model = plotModel;
  172. }
  173. break;
  174. case "湿度曲线":
  175. {
  176. plotModel.Series.Clear();
  177. plotModel = new PlotModel() { Title = "湿度曲线" };
  178. chartGrid.Visibility = Visibility.Visible;
  179. List<DataPoint> ww = new List<DataPoint>();
  180. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐湿度", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  181. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  182. {
  183. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.CondensateWaterHumidity));
  184. });
  185. line_5.Points.AddRange(ww);
  186. if (!(plotModel.Axes.Count > 0))
  187. {
  188. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  189. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "湿度", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  190. }
  191. plotModel.Series.Add(line_5);
  192. plotModel.InvalidatePlot(true);//重新加载曲线
  193. chartView.Model = plotModel;
  194. }
  195. break;
  196. case "反应釜角度曲线":
  197. {
  198. plotModel.Series.Clear();
  199. plotModel = new PlotModel() { Title = "反应釜角度曲线" };
  200. chartGrid.Visibility = Visibility.Visible;
  201. List<DataPoint> ww = new List<DataPoint>();
  202. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "反应釜角度", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  203. SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
  204. {
  205. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ReactEncoderValue));
  206. });
  207. line_5.Points.AddRange(ww);
  208. if (!(plotModel.Axes.Count > 0))
  209. {
  210. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  211. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "角度/°", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  212. }
  213. plotModel.Series.Add(line_5);
  214. plotModel.InvalidatePlot(true);//重新加载曲线
  215. chartView.Model = plotModel;
  216. }
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. private void Button_Click(object sender, RoutedEventArgs e)
  223. {
  224. chartGrid.Visibility = Visibility.Collapsed;
  225. ooo.Visibility = Visibility.Visible;
  226. plotModel.Axes.Clear();
  227. plotModel.Series.Clear();
  228. plotModel.InvalidatePlot(true);
  229. chartView.Model = plotModel;
  230. }
  231. }
  232. }