|
- using LiveCharts.Definitions.Charts;
- using LiveCharts.Wpf;
- using OxyPlot.Axes;
- using OxyPlot;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using ThingsGateway.Foundation.Core;
- using BPASmartClient.Academy._50L;
-
- namespace BPASmartClient.Academy.View
- {
- /// <summary>
- /// DeviceChartView.xaml 的交互逻辑
- /// </summary>
- public partial class DeviceChart50LView : UserControl
- {
- public DeviceChart50LView()
- {
- InitializeComponent();
- //this.DataContext = DeviceChart50LViewModel.GetInstance;
- }
-
-
- public PlotModel plotModel { get; set; } = new PlotModel();
- private void DataView_CLick(object sender, MouseButtonEventArgs e)
- {
- ooo.Visibility = Visibility.Collapsed;
- double min = DateTimeAxis.ToDouble(System.DateTime.Now.AddMinutes(-10));
- double max = DateTimeAxis.ToDouble(System.DateTime.Now);
- double maxrange = max - min;
- CartesianChart liveCharts = sender as CartesianChart;
-
- switch (liveCharts.ToolTip)
- {
- case "温度曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "温度曲线" };
- chartGrid.Visibility = Visibility.Visible;
- 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 };
- 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 };
- List<DataPoint> twValues = new List<DataPoint>();
- List<DataPoint> tvValues = new List<DataPoint>();
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.Temperature));
- tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.CondensateWaterTemperature));
-
- });
- templine.Points.AddRange(twValues);
- templine_1.Points.AddRange(tvValues);
- //line_2.Points.AddRange(tmValues);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "温度/℃", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
- }
- plotModel.Series.Add(templine);
- plotModel.Series.Add(templine_1);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
- case "压力曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "反应釜蒸汽压力曲线" };
- chartGrid.Visibility = Visibility.Visible;
- 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 };
- 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 };
- List<DataPoint> steamPressure = new List<DataPoint>();
- List<DataPoint> reactPressure = new List<DataPoint>();
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- steamPressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.SteamPressure));
- reactPressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ReactPressure));
- });
- line.Points.AddRange(steamPressure);
- line2.Points.AddRange(reactPressure);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "压力/Mpa", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
- }
- plotModel.Series.Add(line);
- plotModel.Series.Add(line2);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
- case "比例阀开度曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "比例阀开度曲线" };
- chartGrid.Visibility = Visibility.Visible;
- 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 };
- List<DataPoint> open = new List<DataPoint>();
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ProportionalValveOpening));
-
- });
- line.Points.AddRange(open);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max, MaximumRange = maxrange });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "比例阀开度/%", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2"), IsZoomEnabled = false });
- }
- plotModel.Series.Add(line);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
-
- case "流量曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "流量曲线" };
- chartGrid.Visibility = Visibility.Visible;
- 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 };
- 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 };
- List<DataPoint> twValues = new List<DataPoint>();
- List<DataPoint> tvValues = new List<DataPoint>();
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.SteamFlowRate));
- tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.NegativePressureFlowRate));
-
- });
- templine.Points.AddRange(twValues);
- templine_1.Points.AddRange(tvValues);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "流量", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
- }
- plotModel.Series.Add(templine);
- plotModel.Series.Add(templine_1);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
- case "重量曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "重量曲线" };
- chartGrid.Visibility = Visibility.Visible;
- List<DataPoint> ww = new List<DataPoint>();
- List<DataPoint> ww1 = new List<DataPoint>();
- OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
- OxyPlot.Series.LineSeries line_6 = new OxyPlot.Series.LineSeries() { Title = "卤水罐重量", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
-
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.WeighingWaterTankWeight));
- ww1.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.BrineTankWeight));
- });
- line_5.Points.AddRange(ww);
- line_6.Points.AddRange(ww1);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "重量/kg", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
- }
- plotModel.Series.Add(line_5);
- plotModel.Series.Add(line_6);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
- case "湿度曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "湿度曲线" };
- chartGrid.Visibility = Visibility.Visible;
- List<DataPoint> ww = new List<DataPoint>();
- OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐湿度", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
-
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.CondensateWaterHumidity));
- });
- line_5.Points.AddRange(ww);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "湿度", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
- }
- plotModel.Series.Add(line_5);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
- case "反应釜角度曲线":
- {
- plotModel.Series.Clear();
- plotModel = new PlotModel() { Title = "反应釜角度曲线" };
- chartGrid.Visibility = Visibility.Visible;
- List<DataPoint> ww = new List<DataPoint>();
- OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "反应釜角度", Color = OxyColor.FromRgb(110, 79, 79), LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End };
-
- SqliteOperate.GetInstance.QueryableById(PlcControl.GetInstance.id).ForEach(t =>
- {
- ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Createtime), t.ReactEncoderValue));
- });
- line_5.Points.AddRange(ww);
- if (!(plotModel.Axes.Count > 0))
- {
- plotModel.Axes.Add(new DateTimeAxis() { Position = OxyPlot.Axes.AxisPosition.Bottom, Title = "时间/s", StringFormat = "hh:mm:ss", Minimum = min, Maximum = max });
- plotModel.Axes.Add(new LinearAxis() { Key = "y1", Title = "角度/°", Position = OxyPlot.Axes.AxisPosition.Left, LabelFormatter = value => value.ToString("f2") });
- }
- plotModel.Series.Add(line_5);
- plotModel.InvalidatePlot(true);//重新加载曲线
- chartView.Model = plotModel;
- }
- break;
- default:
- break;
- }
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- chartGrid.Visibility = Visibility.Collapsed;
- ooo.Visibility = Visibility.Visible;
- plotModel.Axes.Clear();
- plotModel.Series.Clear();
- plotModel.InvalidatePlot(true);
- chartView.Model = plotModel;
- }
- }
- }
|