public ObservableCollection<DataPoint> dpList { get; set; } = new ObservableCollection<DataPoint>();
public ObservableCollection<DataPoint> ReferenceDpList { get; set; } = new ObservableCollection<DataPoint>();
void CallbackFunction(IntPtr tick, int length)
{
try
{
if (length <= 0) { return; }
double X = 190;
dpList.Clear();
ReferenceDpList.Clear();
List<double> dList = new List<double>();
int c = 9102 * 3 + 7;//((1100-190)/0.2+1)*2
for (int i = 7; i < c; i++)
{
int Y = Marshal.ReadByte(tick, i) * 65536 + Marshal.ReadByte(tick, i + 1) * 256 + Marshal.ReadByte(tick, i + 2);
dList.Add(Y);
if (i <= 13657) dpList.Add(new DataPoint(X, Y));
else { ReferenceDpList.Add(new DataPoint(X, Y)); }
if (X == double.Parse("1100"))
{
X = 190;
}
else
{
X = Convert.ToDouble((X + 0.2).ToString("N2")); //保留2位小数
}
i += 2;
}
Thread.Sleep(500);
PlotModel plotModel = new PlotModel { PlotType = PlotType.Cartesian, PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1), };
var l = new Legend
{
LegendPosition = LegendPosition.TopLeft,
LegendOrientation = LegendOrientation.Horizontal,
LegendPlacement = LegendPlacement.Outside
};
plotM
wpf oxyPlot 峰值画线标注
于 2023-06-20 16:16:27 首次发布
该代码段展示了一个处理数据并使用OxyPlot库创建图表的过程。它从内存缓冲区读取数据,将其转换为DataPoint对象,并分为两组。然后清除并填充两个ObservableCollection,分别用于主数据和参考数据。接着,它构建了一个PlotModel,定义了坐标轴,添加了图例,并创建了线性系列。最后,根据特定条件添加垂直注解,并更新UI中的图表模型。

最低0.47元/天 解锁文章
2532

被折叠的 条评论
为什么被折叠?



