图表x轴显示优化
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user