我正在使用 Oxyplot 中的 AreaSeries 来绘制两点之间的范围,并希望跟踪器在悬停时显示它们。通过为 DataPoints 创建自定义类并相应地更改 TrackerFormat,我实现了使 Tracker 与其他系列一起显示自定义属性。这是一个例子:
public class CommentPoint : IScatterPointProvider
{
public CommentPoint(double x, double y, string text)
{
X = x; Y = y; Text = text;
}
public double X, Y;
public string Text { get; set; }
public ScatterPoint GetScatterPoint()
{
return new ScatterPoint(X, Y);
}
}
和 TrackerFormat:
Series.TrackerFormatString = "{2}\n{Text}";
但是,这仅在添加新点数组作为系列的 ItemSource 时才有效。使用 Line/ScatterSeries 很容易,因为它们只需要一个点列表。但是 AreaSeries 需要绘制 2 个点。
我尝试将这些自定义点的二维数组添加为 ItemSource:
public class AreaPoint : IDataPointProvider
{
public AreaPoint(double x, double y, double y2)
{
X = x; Y1 = y; Y2 = y2;
}
public double X { get; set; }
public double Y1 { get; set; }
public double Y2 { get; set; }
public DataPoint GetDataPoint()
{
return new DataPoint(X, Y1);
}
}
所以基本上:
AreaPoint[,] points = new AreaPoint[2,amount.Count]
AreaPoint[0,i] = new AreaPoint(x,y,y2);
....
Series.ItemSource = points;
这不起作用,我收到一个错误“不是一维数组”。
接下来我尝试通过 GetDataPoint 方法直接添加点:
Series.Points.Add(new AreaPoint(x,y,y2).GetDataPoint());
Series.Points2.Add(new AreaPoint(x2,y2,y3).GetDataPoint());
Series.TrackerFormatString = "{2}\n{4}\n{Y2}";
这适用于 AreaSeries 被正确绘制,但 Tracker 不会显示我的自定义属性。
所以我想我的问题是,如何将自定义 ItemSource 添加到 AreaSeries?