|
|
@ -4,13 +4,16 @@ using LiveChartsCore.Kernel.Sketches; |
|
|
|
using LiveChartsCore.SkiaSharpView; |
|
|
|
using LiveChartsCore.SkiaSharpView.Painting; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
using ScottPlot; |
|
|
|
using ScottPlot.Plottables; |
|
|
|
using ScottPlot.Statistics; |
|
|
|
using SkiaSharp; |
|
|
|
using SunlightCentralizedControlManagement_SCCM_.ViewModel; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder; |
|
|
|
using System.Linq; |
|
|
|
using System.Runtime.Serialization; |
|
|
|
using System.Text; |
|
|
@ -33,23 +36,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls |
|
|
|
/// <summary>
|
|
|
|
/// info.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class info : UserControl |
|
|
|
public partial class info : UserControl, INotifyPropertyChanged |
|
|
|
{ |
|
|
|
public info() |
|
|
|
public event PropertyChangedEventHandler PropertyChanged; |
|
|
|
protected virtual void OnPropertyChanged(string propertyName) |
|
|
|
{ |
|
|
|
InitializeComponent(); |
|
|
|
DataContext = this; //new infoModel();
|
|
|
|
if (PropertyChanged != null) |
|
|
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
|
|
|
} |
|
|
|
|
|
|
|
public void DataAdd() |
|
|
|
public void RaisePropertyChanged(string propertyName) |
|
|
|
{ |
|
|
|
if (PropertyChanged != null) |
|
|
|
{ |
|
|
|
if (propertyName != null) |
|
|
|
{ |
|
|
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
private readonly Random _random = new Random(); |
|
|
|
private readonly List<DateTimePoint> _values = new List<DateTimePoint>(); |
|
|
|
private readonly DateTimeAxis _customAxis; |
|
|
|
public ObservableCollection<ISeries> Series { get; set; } |
|
|
|
public static ObservableCollection<ObservableValue> ObservableValues { get; set; } |
|
|
|
private ObservableCollection<DateTimePoint> MTH_values = new ObservableCollection<DateTimePoint>(); |
|
|
|
|
|
|
|
public ObservableCollection<ISeries> _series { get; set; } |
|
|
|
public ObservableCollection<ISeries> Series |
|
|
|
{ |
|
|
|
get => _series; |
|
|
|
set |
|
|
|
{ |
|
|
|
_series = value; |
|
|
|
OnPropertyChanged(nameof(Series)); |
|
|
|
} |
|
|
|
} |
|
|
|
//x轴时间格式
|
|
|
|
public Axis[] XAxes { get; set; } = |
|
|
|
{ |
|
|
@ -83,30 +99,50 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
private static ObservableCollection<DateTimePoint> MTH_values; |
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e) |
|
|
|
public info() |
|
|
|
{ |
|
|
|
var MTH_items = new List<DateTimePoint>(); |
|
|
|
MTH_values = new ObservableCollection<DateTimePoint>(MTH_items); |
|
|
|
InitializeComponent(); |
|
|
|
DataContext = this; |
|
|
|
} |
|
|
|
|
|
|
|
Series = new ObservableCollection<ISeries> |
|
|
|
{ |
|
|
|
new LineSeries<DateTimePoint> |
|
|
|
{ |
|
|
|
Name = Properties.Resources.Temperature, |
|
|
|
Values = MTH_values, |
|
|
|
Stroke = new SolidColorPaint(s_red, 2), |
|
|
|
GeometrySize = 0, |
|
|
|
GeometryStroke = new SolidColorPaint(s_red, 2), |
|
|
|
Fill = null, |
|
|
|
LineSmoothness = 0, |
|
|
|
ScalesYAt = 2, |
|
|
|
} |
|
|
|
}; |
|
|
|
public void DataAdd(double dat) |
|
|
|
{ |
|
|
|
DateTime dateTime = DateTime.Now; |
|
|
|
|
|
|
|
Dispatcher.Invoke(() => |
|
|
|
{ |
|
|
|
// 添加新数据点
|
|
|
|
MTH_values.Add(new DateTimePoint(dateTime, dat)); |
|
|
|
// 更新X轴范围,始终保持最近6小时
|
|
|
|
XAxes[0].MinLimit = dateTime.AddHours(-6).Ticks; |
|
|
|
XAxes[0].MaxLimit = dateTime.AddMinutes(1).Ticks; |
|
|
|
// 移除6小时前的旧数据
|
|
|
|
while (MTH_values.Count > 0 && |
|
|
|
MTH_values[0].DateTime < dateTime.AddHours(-6)) |
|
|
|
{ |
|
|
|
MTH_values.RemoveAt(0); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e) |
|
|
|
{ |
|
|
|
// 初始化系列
|
|
|
|
Series = new ObservableCollection<ISeries> |
|
|
|
{ |
|
|
|
new LineSeries<DateTimePoint> |
|
|
|
{ |
|
|
|
Name = Properties.Resources.Temperature, |
|
|
|
Values = MTH_values, |
|
|
|
Stroke = new SolidColorPaint(s_red, 2), |
|
|
|
GeometrySize = 0, |
|
|
|
GeometryStroke = new SolidColorPaint(s_red, 2), |
|
|
|
Fill = null, |
|
|
|
LineSmoothness = 0, |
|
|
|
ScalesYAt = 0, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|