diff --git a/ViewModel/CurveDiagramViewModel.cs b/ViewModel/CurveDiagramViewModel.cs index f40c314..ebfa388 100644 --- a/ViewModel/CurveDiagramViewModel.cs +++ b/ViewModel/CurveDiagramViewModel.cs @@ -17,32 +17,27 @@ using System.Xml.Linq; using SkiaSharp; using LiveChartsCore.Defaults; using static System.Net.WebRequestMethods; +using System.Collections.ObjectModel; namespace DyeingComputer.ViewModel { public partial class CurveDiagramViewModel : ObservableObject//ViewModelBase { - public ISeries[] Series { get; set; } = - { - new LineSeries - { - Name = Properties.Resources.Temperature +"2", - Values = new DateTimePoint[] + /* public ISeries[] Series { get; set; } = + { + new LineSeries { - new DateTimePoint(Convert.ToDateTime( "2024-01-01 09:08:00"), 24), - new DateTimePoint(Convert.ToDateTime( "2024-01-02 09:08:00"), 57), - new DateTimePoint(Convert.ToDateTime( "2024-01-03 09:08:00"), 67), - new DateTimePoint(Convert.ToDateTime( "2024-01-04 09:08:00"), 32), - new DateTimePoint(Convert.ToDateTime( "2024-01-05 09:08:00"), 57), - new DateTimePoint(Convert.ToDateTime( "2024-01-06 09:08:00"), 27), - new DateTimePoint(Convert.ToDateTime( "2024-01-07 09:08:00"), 57), - new DateTimePoint(Convert.ToDateTime( "2024-01-8 09:08:00"), 17), - }, - Stroke = new SolidColorPaint(s_blue, 2), - GeometrySize = 1, - GeometryStroke = new SolidColorPaint(s_blue, 2), + Name = Properties.Resources.Temperature +"1", + Values = new DateTimePoint[] + { + new DateTimePoint(Convert.ToDateTime( "2024-01-01 09:08:00"), 24), + new DateTimePoint(Convert.ToDateTime( "2024-01-02 09:08:00"), 57), + new DateTimePoint(Convert.ToDateTime( "2024-01-03 09:08:00"), 67), + }, + Stroke = new SolidColorPaint(s_blue, 2), + GeometrySize = 2, + GeometryStroke = new SolidColorPaint(s_blue, 2), Fill = null, - LineSmoothness = 0, ScalesYAt = 0, }, @@ -62,7 +57,7 @@ namespace DyeingComputer.ViewModel }, Fill = null, Stroke = new SolidColorPaint(s_blue, 2), - GeometrySize = 0, + GeometrySize = 2, GeometryStroke = new SolidColorPaint(s_blue, 2), LineSmoothness = 0, ScalesYAt = 0, @@ -70,7 +65,7 @@ namespace DyeingComputer.ViewModel new LineSeries { - Name = Properties.Resources.Flowmeter, + Name = Properties.Resources.WaterLevel, Values = new DateTimePoint[] { new DateTimePoint(Convert.ToDateTime( "2024-01-01 09:08:00"), 4), @@ -85,14 +80,14 @@ namespace DyeingComputer.ViewModel Fill = null, Stroke = new SolidColorPaint(s_red, 2), - GeometrySize = 0, + GeometrySize = 2, GeometryStroke = new SolidColorPaint(s_red, 2), LineSmoothness = 0, ScalesYAt = 1, } - }; - + };*/ + public ISeries[] Series { get; set; } //x轴时间格式 public Axis[] XAxes { get; set; } = { @@ -107,7 +102,6 @@ namespace DyeingComputer.ViewModel private static readonly SKColor s_blue = new SKColor(25, 118, 210); private static readonly SKColor s_red = new SKColor(229, 57, 53); private static readonly SKColor s_yellow = new SKColor(198, 167, 0); - public ICartesianAxis[] YAxes { get; set; } ={ new Axis //y在此轴上缩放 { @@ -141,9 +135,55 @@ namespace DyeingComputer.ViewModel }, //液位轴 }; + private readonly Random _r = new Random(); + private readonly ObservableCollection _values; + private DateTimePoint _current; + + private SQLiteHelper SQLiteHelpers = null; //定义数据库 + private readonly string ChartAdress = Environment.CurrentDirectory + "\\DataBase\\Chart.db"; //数据库路径 + DataTable CDB = new DataTable(); + private int CDB_Count;//长度 + public CurveDiagramViewModel() { - + // if (MainWindowViewModel.WorkNumder.ToString() != "----------") + { + SQLiteHelpers = new SQLiteHelper(ChartAdress); //数据库连接路径 + SQLiteHelpers.Open(); //打开数据库 + CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart where DYELOT = '" + MainWindowViewModel.WorkNumder + "'order by Time", null).Tables[0]; + CDB = SQLiteHelpers.ExecuteDataSet("select * from Chart order by Time", null).Tables[0]; + SQLiteHelpers.Close(); + CDB_Count = CDB.Rows.Count; + } + + + var items = new List(); + for (var i = 0; i < CDB_Count; i++) + { + // _current += _r.Next(-9, 10); + // CDB.Rows[i].Field("varchar") + items.Add(new DateTimePoint(Convert.ToDateTime(CDB.Rows[i].Field("Time")), CDB.Rows[i].Field("MTT"))); + } + _values = new ObservableCollection(items); + + Series = new ISeries[] + { + new LineSeries + { + Name = Properties.Resources.Temperature +"1", + Values = _values, + Stroke = new SolidColorPaint(s_blue, 2), + GeometrySize = 2, + GeometryStroke = new SolidColorPaint(s_blue, 2), + Fill = null, + LineSmoothness = 0, + ScalesYAt = 0, + }, + }; + + + + } } }