染色机计算机
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.

189 lines
8.2 KiB

using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DyeingComputer.UserClass.SqliteHelper;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView.Painting;
using ScottPlot.Colormaps;
using System.Drawing;
using System.Windows.Media.TextFormatting;
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<DateTimePoint>
{
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,
},
new LineSeries<DateTimePoint>
{
Name = Properties.Resources.Temperature +"2",
Values = new DateTimePoint[]
{
new DateTimePoint(Convert.ToDateTime( "2024-01-01 09:08:00"), 424),
new DateTimePoint(Convert.ToDateTime( "2024-01-02 09:08:00"), 57),
new DateTimePoint(Convert.ToDateTime( "2024-01-03 09:08:00"), 647),
new DateTimePoint(Convert.ToDateTime( "2024-01-04 09:08:00"), 532),
new DateTimePoint(Convert.ToDateTime( "2024-01-05 09:08:00"), 57),
new DateTimePoint(Convert.ToDateTime( "2024-01-06 09:08:00"), 287),
new DateTimePoint(Convert.ToDateTime( "2024-01-07 09:08:00"), 57),
new DateTimePoint(Convert.ToDateTime( "2024-01-8 09:08:00"), 17),
},
Fill = null,
Stroke = new SolidColorPaint(s_blue, 2),
GeometrySize = 2,
GeometryStroke = new SolidColorPaint(s_blue, 2),
LineSmoothness = 0,
ScalesYAt = 0,
},
new LineSeries<DateTimePoint>
{
Name = Properties.Resources.WaterLevel,
Values = new DateTimePoint[]
{
new DateTimePoint(Convert.ToDateTime( "2024-01-01 09:08:00"), 4),
new DateTimePoint(Convert.ToDateTime( "2024-01-02 09:08:00"), 57),
new DateTimePoint(Convert.ToDateTime( "2024-01-03 09:08:00"), 647),
new DateTimePoint(Convert.ToDateTime( "2024-01-04 09:08:00"), 5732),
new DateTimePoint(Convert.ToDateTime( "2024-01-05 09:08:00"), 5457),
new DateTimePoint(Convert.ToDateTime( "2024-01-06 09:08:00"), 2257),
new DateTimePoint(Convert.ToDateTime( "2024-01-07 09:08:00"), 57),
new DateTimePoint(Convert.ToDateTime( "2024-01-8 09:08:00"), 517),
},
Fill = null,
Stroke = new SolidColorPaint(s_red, 2),
GeometrySize = 2,
GeometryStroke = new SolidColorPaint(s_red, 2),
LineSmoothness = 0,
ScalesYAt = 1,
}
};*/
public ISeries[] Series { get; set; }
//x轴时间格式
public Axis[] XAxes { get; set; } =
{
new DateTimeAxis(TimeSpan.FromSeconds(5) , date => date.ToString("yyyy-MM-dd HH:mm"))
{
CrosshairLabelsBackground = SKColors.DarkGray.AsLvcColor(),
CrosshairLabelsPaint = new SolidColorPaint(SKColors.DarkSlateBlue, 1),
CrosshairPaint = new SolidColorPaint(SKColors.DarkSlateGray, 1),
},
};
//颜色
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在此轴上缩放
{
Name = Properties.Resources.Temperature +" ( °C )",
NameTextSize = 24,
NamePaint = new SolidColorPaint(s_blue),
NamePadding = new LiveChartsCore.Drawing.Padding(0, 20),
Padding = new LiveChartsCore.Drawing.Padding(0, 0, 20, 0),
TextSize = 16,
LabelsPaint = new SolidColorPaint(s_blue),
TicksPaint = new SolidColorPaint(s_blue),
SubticksPaint = new SolidColorPaint(s_blue),
DrawTicksPath = true,
CrosshairSnapEnabled = true
},//温度轴
new Axis // the "hundreds" series will be scaled on this axis
{
Name = Properties.Resources.Flowmeter +" ( L )",
NameTextSize = 24,
NamePaint = new SolidColorPaint(s_red),
NamePadding = new LiveChartsCore.Drawing.Padding(0, 20),
Padding = new LiveChartsCore.Drawing.Padding(20, 0, 0, 0),
TextSize = 16,
LabelsPaint = new SolidColorPaint(s_red),
TicksPaint = new SolidColorPaint(s_red),
SubticksPaint = new SolidColorPaint(s_red),
DrawTicksPath = true,
ShowSeparatorLines = false,
CrosshairSnapEnabled = true,
Position = LiveChartsCore.Measure.AxisPosition.End
}, //液位轴
};
private readonly Random _r = new Random();
private readonly ObservableCollection<DateTimePoint> _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<DateTimePoint>();
for (var i = 0; i < CDB_Count; i++)
{
// _current += _r.Next(-9, 10);
// CDB.Rows[i].Field<string>("varchar")
items.Add(new DateTimePoint(Convert.ToDateTime(CDB.Rows[i].Field<string>("Time")), CDB.Rows[i].Field<double>("MTT")));
}
_values = new ObservableCollection<DateTimePoint>(items);
Series = new ISeries[]
{
new LineSeries<DateTimePoint>
{
Name = Properties.Resources.Temperature +"1",
Values = _values,
Stroke = new SolidColorPaint(s_blue, 2),
GeometrySize = 0,
GeometryStroke = new SolidColorPaint(s_blue, 2),
Fill = null,
LineSmoothness = 0,
ScalesYAt = 0,
},
};
}
}
}
}