在VariableHistoryView中增强图表显示

This commit is contained in:
2025-10-03 11:58:15 +08:00
parent 6ff4ef1c00
commit 65c7232efa
2 changed files with 21 additions and 19 deletions

View File

@@ -108,21 +108,21 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
private void OnVariableValueChanged(object? sender, VariableValueChangedEventArgs e)
{
if (e.Variable.Id != CurrentVariable.Id)
{
return;
}
var variableHistory = new VariableHistoryDto()
{
VariableId = CurrentVariable.Id,
Timestamp = DateTime.Now,
Value = e.Variable.DataValue
};
_variableHistoryList.Add(variableHistory);
// 更新图表数据
UpdateChartData();
// if (e.Variable.Id != CurrentVariable.Id)
// {
// return;
// }
//
// var variableHistory = new VariableHistoryDto()
// {
// VariableId = CurrentVariable.Id,
// Timestamp = DateTime.Now,
// Value = e.Variable.DataValue
// };
// _variableHistoryList.Add(variableHistory);
//
// // 更新图表数据
// UpdateChartData();
}
/// <summary>
@@ -256,11 +256,12 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
// 创建线性序列
var series = new LineSeries<DateTimePoint>
{
Name = "变量值",
Name = CurrentVariable?.Name ?? "变量值",
Values = values,
Fill = null,
Stroke = new SolidColorPaint(new SKColor(41, 128, 185)) { StrokeThickness = 2 },
GeometrySize = 0 // 显示数据点,只显示线条
GeometrySize = 6, // 显示数据点,圆点大小为6
LineSmoothness = 0 // 使用直线连接点,也可以设为其他值实现曲线
};
// 更新序列集合
@@ -279,7 +280,8 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
{
new Axis
{
Name = "值"
Name = CurrentVariable?.Name ?? "值",
MinLimit = 0 // 设置Y轴从0开始
}
};

View File

@@ -120,7 +120,7 @@
SelectionMode="Single"
Style="{StaticResource DataGridBaseStyle}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Value}" Header="" />
<DataGridTextColumn Binding="{Binding Value}" Header="{Binding DataContext.CurrentVariable.Name, RelativeSource={RelativeSource AncestorType=UserControl}, FallbackValue='值'}" />
<DataGridTextColumn
Binding="{Binding Timestamp, StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}"
Header="时间戳"