终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

179 行
10 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. namespace BPASmartClient.Academy.View
  21. {
  22. /// <summary>
  23. /// DeviceChartView.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class DeviceChart50LView : UserControl
  26. {
  27. public DeviceChart50LView()
  28. {
  29. InitializeComponent();
  30. }
  31. public PlotModel plotModel { get; set; } = new PlotModel();
  32. private void DataView_CLick(object sender, MouseButtonEventArgs e)
  33. {
  34. ooo.Visibility = Visibility.Collapsed;
  35. double min = DateTimeAxis.ToDouble(System.DateTime.Now.AddMinutes(-10));
  36. double max = DateTimeAxis.ToDouble(System.DateTime.Now);
  37. double maxrange = max - min;
  38. CartesianChart liveCharts = sender as CartesianChart;
  39. switch (liveCharts.ToolTip)
  40. {
  41. case "温度曲线":
  42. plotModel.Series.Clear();
  43. plotModel = new PlotModel() { Title = "温度曲线" };
  44. chartGrid.Visibility = Visibility.Visible;
  45. 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 };
  46. OxyPlot.Series.LineSeries line_1 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜排气温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  47. OxyPlot.Series.LineSeries line_2 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "配料罐温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  48. List<DataPoint> twValues = new List<DataPoint>();
  49. List<DataPoint> tvValues = new List<DataPoint>();
  50. List<DataPoint> tmValues = new List<DataPoint>();
  51. Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  52. {
  53. twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempWok));
  54. tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempVent));
  55. tmValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempMaterial));
  56. });
  57. line.Points.AddRange(twValues);
  58. line_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(line);
  66. plotModel.Series.Add(line_1);
  67. plotModel.Series.Add(line_2);
  68. plotModel.InvalidatePlot(true);//重新加载曲线
  69. chartView.Model = plotModel;
  70. break;
  71. case "转速曲线":
  72. plotModel.Series.Clear();
  73. plotModel = new PlotModel() { Title = "转速曲线" };
  74. chartGrid.Visibility = Visibility.Visible;
  75. OxyPlot.Series.LineSeries line_3 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜转速", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  76. OxyPlot.Series.LineSeries line_4 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "配料罐转速", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  77. List<DataPoint> m101 = new List<DataPoint>();
  78. List<DataPoint> m102 = new List<DataPoint>();
  79. Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  80. {
  81. m101.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M101_Speed));
  82. m102.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M102_Speed));
  83. });
  84. line_3.Points.AddRange(m101);
  85. line_4.Points.AddRange(m102);
  86. if (!(plotModel.Axes.Count > 0))
  87. {
  88. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  89. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "转速/rpm", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  90. }
  91. plotModel.Series.Add(line_3);
  92. plotModel.Series.Add(line_4);
  93. plotModel.InvalidatePlot(true);//重新加载曲线
  94. chartView.Model = plotModel;
  95. break;
  96. //case "比例阀开度曲线":
  97. // plotModel.Series.Clear();
  98. // plotModel = new PlotModel() { Title = "比例阀开度曲线" };
  99. // chartGrid.Visibility = Visibility.Visible;
  100. // List<DataPoint> open = new List<DataPoint>();
  101. // Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  102. // {
  103. // open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.OpenValve));
  104. // });
  105. // line.Points.AddRange(open);
  106. // if (!(plotModel.Axes.Count > 0))
  107. // {
  108. // plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  109. // plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/挡", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
  110. // }
  111. // plotModel.Series.Add(line);
  112. // plotModel.InvalidatePlot(true);//重新加载曲线
  113. // chartView.Model = plotModel;
  114. // break;
  115. //case "压力曲线":
  116. // plotModel.Series.Clear();
  117. // plotModel = new PlotModel() { Title = "反应釜压力曲线" };
  118. // chartGrid.Visibility = Visibility.Visible;
  119. // List<DataPoint> pressure = new List<DataPoint>();
  120. // Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  121. // {
  122. // pressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok));
  123. // });
  124. // line.Points.AddRange(pressure);
  125. // if (!(plotModel.Axes.Count > 0))
  126. // {
  127. // plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  128. // plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "反应釜压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
  129. // }
  130. // plotModel.Series.Add(line);
  131. // plotModel.InvalidatePlot(true);//重新加载曲线
  132. // chartView.Model = plotModel;
  133. // break;
  134. case "重量曲线":
  135. plotModel.Series.Clear();
  136. plotModel = new PlotModel() { Title = "冷却水罐重量曲线" };
  137. chartGrid.Visibility = Visibility.Visible;
  138. List<DataPoint> ww = new List<DataPoint>();
  139. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(0, 0, 0), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  140. Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  141. {
  142. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.WeightWok));
  143. });
  144. line_5.Points.AddRange(ww);
  145. if (!(plotModel.Axes.Count > 0))
  146. {
  147. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  148. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "冷却水罐重量/kg", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  149. }
  150. plotModel.Series.Add(line_5);
  151. plotModel.InvalidatePlot(true);//重新加载曲线
  152. chartView.Model = plotModel;
  153. break;
  154. default:
  155. break;
  156. }
  157. }
  158. private void Button_Click(object sender, RoutedEventArgs e)
  159. {
  160. chartGrid.Visibility = Visibility.Collapsed;
  161. ooo.Visibility = Visibility.Visible;
  162. plotModel.Axes.Clear();
  163. plotModel.Series.Clear();
  164. plotModel.InvalidatePlot(true);
  165. chartView.Model = plotModel;
  166. }
  167. }
  168. }