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; namespace BPASmartClient.Academy.View { /// /// DeviceChartView.xaml 的交互逻辑 /// public partial class DeviceChartView : UserControl { public DeviceChartView() { InitializeComponent(); } 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 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 line_1 = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "反应釜排气温度", MarkerFill = OxyColor.FromRgb(110, 79, 79), MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End }; 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 }; List twValues = new List(); List tvValues = new List(); List tmValues = new List(); Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t => { twValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempWok)); tvValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempVent)); tmValues.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.TempMaterial)); }); line.Points.AddRange(twValues); line_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(line); plotModel.Series.Add(line_1); plotModel.Series.Add(line_2); plotModel.InvalidatePlot(true);//重新加载曲线 chartView.Model = plotModel; break; case "转速曲线": plotModel.Series.Clear(); plotModel = new PlotModel() { Title = "转速曲线" }; chartGrid.Visibility = Visibility.Visible; 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 }; 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 }; List m101 = new List(); List m102 = new List(); Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t => { m101.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M101_Speed)); m102.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.M102_Speed)); }); line_3.Points.AddRange(m101); line_4.Points.AddRange(m102); 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_3); plotModel.Series.Add(line_4); plotModel.InvalidatePlot(true);//重新加载曲线 chartView.Model = plotModel; break; case "比例阀开度曲线": plotModel.Series.Clear(); plotModel = new PlotModel() { Title = "比例阀开度曲线" }; OxyPlot.Series.LineSeries line_open = new OxyPlot.Series.LineSeries() { LineStyle = LineStyle.Solid, Title = "比例阀开度", MarkerSize = 2, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End }; chartGrid.Visibility = Visibility.Visible; List open = new List(); Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t => { open.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.OpenValve)); }); line_open.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") }); } plotModel.Series.Add(line_open); plotModel.InvalidatePlot(true);//重新加载曲线 chartView.Model = plotModel; break; case "压力曲线": plotModel.Series.Clear(); plotModel = new PlotModel() { Title = "反应釜压力曲线" }; 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 }; 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 }; chartGrid.Visibility = Visibility.Visible; List pressure = new List(); List pressure_week = new List(); Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t => { pressure.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok)); pressure_week.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.PressureWok_Week)); }); line_pre.Points.AddRange(pressure); line_preweek.Points.AddRange(pressure_week); 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") }); } plotModel.Series.Add(line_pre); plotModel.Series.Add(line_preweek); plotModel.InvalidatePlot(true);//重新加载曲线 chartView.Model = plotModel; break; case "重量曲线": plotModel.Series.Clear(); plotModel = new PlotModel() { Title = "冷却水罐重量曲线" }; chartGrid.Visibility = Visibility.Visible; List ww = new List(); OxyPlot.Series.LineSeries line_5 = new OxyPlot.Series.LineSeries() { Title = "冷却水罐重量", Color = OxyColor.FromRgb(0, 0, 0),LineStyle = LineStyle.Solid, LineLegendPosition = OxyPlot.Series.LineLegendPosition.End }; Sqlite.GetInstance.SelectId(Simens_PLC.GetInstance.id).ForEach(t => { ww.Add(new DataPoint(DateTimeAxis.ToDouble(t.Date), t.WeightWok)); }); 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 = "冷却水罐重量/g", 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; } } }