1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using LiveCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Thick.Base.UI.UiModule
{
public class FixGraphVmUt : INotifyPropertyChanged
{
#region 图表控制
public double YMax { get; set; } = double.NaN;
public double YMin { get; set; } = double.NaN;
public Func<double, string> XFormatter { get; set; }
public Func<double, string> YFormatter { get; set; }
public double XMax { get; set; } = double.NaN;
public ChartValues<double> Values { get; } = new ChartValues<double>();
#endregion
#region 界面统计值
/// <summary>
/// 平均值
/// </summary>
public double Average { get; set; }
/// <summary>
/// 最大值
/// </summary>
public double Max { get; set; }
/// <summary>
/// 最小值
/// </summary>
public double Min { get; set; }
/// <summary>
/// 3sigma
/// </summary>
public double Sigma3 { get; set; }
#endregion
#region 状态
public DateTime Time { get; set; }
public TimeSpan Interval { get; set; }
public double Intervalms { get; set; }
public int Mix { get; set; }
public bool IsPaused { get; set; }
#endregion
/// <summary>
/// 为了画图快,曲线只能显示最多1000个点
/// </summary>
const int TotalValueCountInView = 1000;
public FixGraphVmUt()
{
#region 与数据无关界面参数
XFormatter = (x) =>
{
int index = (int)x;
double s = Interval.TotalSeconds * index;
return $"{s:F1}s";
};
YFormatter = (y) => y.ToString("F1");
Interval = TimeSpan.FromTicks((long)(TimeSpan.TicksPerMillisecond * 1.28));
Intervalms = ((double)(Interval.Ticks)) / TimeSpan.TicksPerMillisecond;
#endregion
Random random = new Random();
List<double> values = new List<double>();
for (int i = 0; i < 1000; i++)
{
double v = (Math.Sin(i * Math.PI / 400.0) * 0.6) * 2 + 72 + (random.NextDouble() - 0.5) * 1;
values.Add(v);
}
Values.AddRange(values);
}
public event PropertyChangedEventHandler PropertyChanged;
}
}