diff --git a/MonitorModule/ViewModels/MonitorViewModel.cs b/MonitorModule/ViewModels/MonitorViewModel.cs
index f2d1bee..4843448 100644
--- a/MonitorModule/ViewModels/MonitorViewModel.cs
+++ b/MonitorModule/ViewModels/MonitorViewModel.cs
@@ -222,10 +222,8 @@ namespace MonitorModule.ViewModels
if (channel == null) return;
- double time = _stopwatch.Elapsed.TotalSeconds;
-
// 记录数据点(线程安全:Record 内部 ConcurrentQueue + Series 操作)
- channel.Record(time, args.Value);
+ channel.Record(args.Time, args.Value);
// 入队数据库批量写入
// CreateTime 使用 args.Time(采样触发时刻),而不是 DateTime.Now(设备响应到达时刻),
@@ -252,13 +250,12 @@ namespace MonitorModule.ViewModels
{
if (!_stopwatch.IsRunning) return;
- double elapsed = _stopwatch.Elapsed.TotalSeconds;
+ var now = DateTime.Now;
var xAxis = Plot.Axes.FirstOrDefault(a => a.Position == AxisPosition.Bottom);
if (xAxis != null)
{
- double window = 10000 * 0.1; // 20s 视窗
- xAxis.Minimum = Math.Max(0, elapsed - window);
- xAxis.Maximum = elapsed + 0.5;
+ xAxis.Minimum = DateTimeAxis.ToDouble(now.AddSeconds(-20));
+ xAxis.Maximum = DateTimeAxis.ToDouble(now.AddSeconds(0.5));
}
Plot.InvalidatePlot(true);
}
@@ -370,10 +367,11 @@ namespace MonitorModule.ViewModels
PlotAreaBorderColor = OxyColors.LightGray,
Background = OxyColors.White
};
- pm.Axes.Add(new LinearAxis
+ pm.Axes.Add(new DateTimeAxis
{
Position = AxisPosition.Bottom,
- Title = "时间 (s)",
+ Title = "时间",
+ StringFormat = "HH:mm:ss",
MajorGridlineStyle = LineStyle.Dot,
MinorGridlineStyle = LineStyle.None
});
@@ -822,7 +820,7 @@ namespace MonitorModule.ViewModels
var recent = channel.DataPoints.ToArray();
var startIdx = Math.Max(0, recent.Length - 10000);
for (int i = startIdx; i < recent.Length; i++)
- channel.Series.Points.Add(new DataPoint(recent[i].Time, recent[i].DisplayValue));
+ channel.Series.Points.Add(new DataPoint(recent[i].Time.ToOADate(), recent[i].DisplayValue));
Plot.Series.Add(channel.Series);
Plot.InvalidatePlot(true);
@@ -846,7 +844,7 @@ namespace MonitorModule.ViewModels
channel.Series.Points.Clear();
var startIdx = Math.Max(0, points.Length - 10000);
for (int i = startIdx; i < points.Length; i++)
- channel.Series.Points.Add(new DataPoint(points[i].Time, points[i].DisplayValue));
+ channel.Series.Points.Add(new DataPoint(points[i].Time.ToOADate(), points[i].DisplayValue));
Plot.InvalidatePlot(true);
}
#endregion
diff --git a/UIShare/UIViewModel/MonitorChannel.cs b/UIShare/UIViewModel/MonitorChannel.cs
index 02bcdc0..514c553 100644
--- a/UIShare/UIViewModel/MonitorChannel.cs
+++ b/UIShare/UIViewModel/MonitorChannel.cs
@@ -1,5 +1,6 @@
using OxyPlot.Series;
using OxyPlot;
+using System;
using System.Collections.Concurrent;
using Prism.Mvvm;
using NCalc;
@@ -52,7 +53,7 @@ namespace UIShare.UIViewModel
// ===== 数据存储 =====
/// 所有采样数据点(线程安全),与 OxyPlot 无关
- public ConcurrentQueue<(double Time, double RawValue, double DisplayValue)> DataPoints { get; } = new();
+ public ConcurrentQueue<(DateTime Time, double RawValue, double DisplayValue)> DataPoints { get; } = new();
/// 最大缓冲数据点数,超出则丢弃最旧的
public int MaxBuffer { get; set; } = 5000;
@@ -67,7 +68,7 @@ namespace UIShare.UIViewModel
// ===== 辅助方法 =====
/// 记录一个数据点:RawValue 经数学变换后得到 DisplayValue,一并入队
- public void Record(double time, double rawValue)
+ public void Record(DateTime time, double rawValue)
{
double displayValue = rawValue;
@@ -82,7 +83,7 @@ namespace UIShare.UIViewModel
// 如果正在显示,同步到 Series
if (_series != null)
{
- _series.Points.Add(new DataPoint(time, displayValue));
+ _series.Points.Add(new DataPoint(time.ToOADate(), displayValue));
while (_series.Points.Count > 10000)
{
_series.Points.RemoveAt(0);