我绘制了某种图表:
var geometry = new StreamGeometry();
using (var ctx = geometry.Open())
{
ctx.BeginFigure(new Point(offset, MyCanvas.Height), false, false);
for (var i = 0; i < interpolated.Count; i++)
{
var x = i * partWidth / interpolated.Count + offset;
ctx.LineTo(new Point(x, MyCanvas.Height - interpolated[i]), true, false);
}
ctx.LineTo(new Point(offset + partWidth, MyCanvas.Height), true, false);
ctx.LineTo(new Point(offset, MyCanvas.Height), true, false);
geometry.FillRule = FillRule.EvenOdd;
geometry.Freeze();
var path = new Path
{
Stroke = Brushes.Black,
StrokeThickness = 1,
Data = geometry,
Fill = Brushes.Black
};
MyCanvas.Children.Add(path);
}
我在interpolated[]
中的所有值= 0..40。
我的画布高度= 50
这就是我得到的:
我不明白,为什么我画的线下面有些点:
var zeroLine = new Line
{
X1 = 0,
X2 = 790,
Y1 = MyCanvas.Height,
Y2 = MyCanvas.Height,
Stroke = Brushes.Coral,
StrokeThickness = 1
};
MyCanvas.Children.Add(zeroLine);
如果MyCanvas.Height值大于我的数据值(可以肯定),则{{1}小于MyCanvas.Height - interpolated[i]
应该总是小于橙色线,对吗?
据我了解,StreamGeometry是否通过设计在给定点之外绘制此零件?可以防止这种情况吗?
答案 0 :(得分:1)
这归因于路径的StrokeLineJoin
,默认情况下为Miter
。
改为将其设置为Round
:
var path = new Path
{
Stroke = Brushes.Black,
StrokeThickness = 1,
StrokeLineJoin = PenLineJoin.Round,
Data = geometry
};
请注意,您也可以使用折线元素来代替具有由许多单行组成的几何路径。