Browse Source

总览信息页面曲线图

master
sc 2 months ago
parent
commit
8b7593dceb
  1. 2
      Properties/Resources.zh-TW.resx
  2. 4
      UserControls/info.xaml
  3. 98
      UserControls/info.xaml.cs
  4. 15
      View/Whole.xaml.cs

2
Properties/Resources.zh-TW.resx

@ -1078,6 +1078,6 @@
<value>輸送異常</value> <value>輸送異常</value>
</data> </data>
<data name="_Auto" xml:space="preserve"> <data name="_Auto" xml:space="preserve">
<value /> <value>手/自動</value>
</data> </data>
</root> </root>

4
UserControls/info.xaml

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.UserControls" xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.UserControls"
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF" xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
mc:Ignorable="d" mc:Ignorable="d"
Loaded="UserControl_Loaded" Loaded="UserControl_Loaded"
d:DesignHeight="400" d:DesignWidth="300" Background="White"> d:DesignHeight="400" d:DesignWidth="300" Background="White">
<Grid Background="#FFBFBFBF"> <Grid Background="#FFBFBFBF">
@ -22,7 +22,7 @@
<local:RoilingTextBlock Foreground="Black" x:Name="Step" Text="NO Information" FontSize="21" Height="30" Margin="120,50,0,0" VerticalAlignment="Top"/> <local:RoilingTextBlock Foreground="Black" x:Name="Step" Text="NO Information" FontSize="21" Height="30" Margin="120,50,0,0" VerticalAlignment="Top"/>
<local:RoilingTextBlock Foreground="Black" x:Name="Message" Text="NO Information" FontSize="21" Height="30" Margin="120,100,0,0" VerticalAlignment="Top"/> <local:RoilingTextBlock Foreground="Black" x:Name="Message" Text="NO Information" FontSize="21" Height="30" Margin="120,100,0,0" VerticalAlignment="Top"/>
<local:RoilingTextBlock Foreground="Black" x:Name="Orders" Text="NO Information" FontSize="21" Height="30" Margin="120,150,0,0" VerticalAlignment="Top"/> <local:RoilingTextBlock Foreground="Black" x:Name="Orders" Text="NO Information" FontSize="21" Height="30" Margin="120,150,0,0" VerticalAlignment="Top"/>
<lvc:CartesianChart x:Name="OscChart" Margin="0,200 ,0,0" EasingFunction="{x:Null}" ZoomMode="PanX" <lvc:CartesianChart x:Name="OscChart" Margin="0,200,0,0" EasingFunction="{x:Null}" ZoomMode="PanX"
Series="{Binding Series}" YAxes="{Binding YAxes}" XAxes="{Binding XAxes}"/> Series="{Binding Series}" YAxes="{Binding YAxes}" XAxes="{Binding XAxes}"/>
</Grid> </Grid>
</Grid> </Grid>

98
UserControls/info.xaml.cs

@ -4,13 +4,16 @@ using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView; using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting; using LiveChartsCore.SkiaSharpView.Painting;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using ScottPlot;
using ScottPlot.Plottables; using ScottPlot.Plottables;
using ScottPlot.Statistics;
using SkiaSharp; using SkiaSharp;
using SunlightCentralizedControlManagement_SCCM_.ViewModel; using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text; using System.Text;
@ -33,23 +36,36 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls
/// <summary> /// <summary>
/// info.xaml 的交互逻辑 /// info.xaml 的交互逻辑
/// </summary> /// </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(); if (PropertyChanged != null)
DataContext = this; //new infoModel(); PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
public void RaisePropertyChanged(string propertyName)
public void DataAdd()
{ {
if (PropertyChanged != null)
{
if (propertyName != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
} }
private readonly Random _random = new Random(); private ObservableCollection<DateTimePoint> MTH_values = new ObservableCollection<DateTimePoint>();
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; }
public ObservableCollection<ISeries> _series { get; set; }
public ObservableCollection<ISeries> Series
{
get => _series;
set
{
_series = value;
OnPropertyChanged(nameof(Series));
}
}
//x轴时间格式 //x轴时间格式
public Axis[] XAxes { get; set; } = public Axis[] XAxes { get; set; } =
{ {
@ -83,30 +99,50 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserControls
}; };
private static ObservableCollection<DateTimePoint> MTH_values; public info()
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{ {
var MTH_items = new List<DateTimePoint>(); InitializeComponent();
MTH_values = new ObservableCollection<DateTimePoint>(MTH_items); DataContext = this;
}
Series = new ObservableCollection<ISeries> public void DataAdd(double dat)
{ {
new LineSeries<DateTimePoint> DateTime dateTime = DateTime.Now;
{
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,
}
};
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,
}
};
} }
}
}
} }

15
View/Whole.xaml.cs

@ -86,16 +86,18 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
} }
} }
int t30S = 0;
private void CountDown() private void CountDown()
{ {
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
{ {
Interval = TimeSpan.FromSeconds(1)//秒 Interval = TimeSpan.FromSeconds(1)//秒
}; };
timer1s.Tick += Tick_Event_1S; timer1s.Tick += Tick_Event_S;
timer1s.Start(); timer1s.Start();
}//时间周期初始化 }//时间周期初始化
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
void Tick_Event_S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{ {
for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++) for (int i = 0; i < MainWindowViewModel.Machines.Rows.Count; i++)
{ {
@ -114,7 +116,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
inf[i].Message.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "Message", i); inf[i].Message.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "Message", i);
inf[i].Orders.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "WorkOrder", i); inf[i].Orders.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "WorkOrder", i);
inf[i].time.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "time", i); inf[i].time.Text = (string)Selet_Machines(MainWindowViewModel.Machines, "time", i);
}
if ((t30S > 30)&&(State_!="800"))
{
t30S = 0;
inf[i].DataAdd((double)Selet_Machines(MainWindowViewModel.Machines, "Temperature", i));
}
else { t30S++; }
}
} }
} }
} }

Loading…
Cancel
Save