终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeviceChartView.xaml.cs 11 KiB

3 月之前
3 月之前
3 月之前
3 月之前
3 月之前
3 月之前
2 月之前
3 月之前
2 月之前
3 月之前
2 月之前
3 月之前
3 月之前
3 月之前
3 月之前
3 月之前
2 月之前
3 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 DeviceChartView : UserControl
  26. {
  27. public DeviceChartView()
  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 = "转速/%", 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. OxyPlot.Series.LineSeries line_open = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "比例阀开度", MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  100. chartGrid.Visibility = Visibility.Visible;
  101. List<DataPoint> open = new List<DataPoint>();
  102. Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  103. {
  104. open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.OpenValve));
  105. });
  106. line_open.Points.AddRange(open);
  107. if (!(plotModel.Axes.Count > 0))
  108. {
  109. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  110. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/挡", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  111. }
  112. plotModel.Series.Add(line_open);
  113. plotModel.InvalidatePlot(true);//重新加载曲线
  114. chartView.Model = plotModel;
  115. break;
  116. case "压力曲线":
  117. plotModel.Series.Clear();
  118. plotModel = new PlotModel() { Title = "反应釜压力曲线" };
  119. OxyPlot.Series.LineSeries line_pre = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜压力", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  120. OxyPlot.Series.LineSeries line_preweek = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜蒸汽压力", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  121. chartGrid.Visibility = Visibility.Visible;
  122. List<DataPoint> pressure = new List<DataPoint>();
  123. List<DataPoint> pressure_week = new List<DataPoint>();
  124. Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  125. {
  126. pressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok));
  127. pressure_week.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok_Week));
  128. });
  129. line_pre.Points.AddRange(pressure);
  130. line_preweek.Points.AddRange(pressure_week);
  131. if (!(plotModel.Axes.Count > 0))
  132. {
  133. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
  134. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "反应釜压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
  135. }
  136. plotModel.Series.Add(line_pre);
  137. plotModel.Series.Add(line_preweek);
  138. plotModel.InvalidatePlot(true);//重新加载曲线
  139. chartView.Model = plotModel;
  140. break;
  141. case "重量曲线":
  142. plotModel.Series.Clear();
  143. plotModel = new PlotModel() { Title = "冷却水罐重量曲线" };
  144. chartGrid.Visibility = Visibility.Visible;
  145. List<DataPoint> ww = new List<DataPoint>();
  146. OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(0, 0, 0),LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
  147. Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t =>
  148. {
  149. ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.WeightWok));
  150. });
  151. line_5.Points.AddRange(ww);
  152. if (!(plotModel.Axes.Count > 0))
  153. {
  154. plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
  155. plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "冷却水罐重量/g", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2")});
  156. }
  157. plotModel.Series.Add(line_5);
  158. plotModel.InvalidatePlot(true);//重新加载曲线
  159. chartView.Model = plotModel;
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. private void Button_Click(object sender, RoutedEventArgs e)
  166. {
  167. chartGrid.Visibility = Visibility.Collapsed;
  168. ooo.Visibility = Visibility.Visible;
  169. plotModel.Axes.Clear();
  170. plotModel.Series.Clear();
  171. plotModel.InvalidatePlot(true);
  172. chartView.Model = plotModel;
  173. }
  174. }
  175. }