2
我正尝试使用WPF编写自己的饼图控件。我创建了一个函数,它返回表示饼图的一部分的Path对象。当我使用它来生成一个图,其中最大的切片是小于或等于它呈现微细图形的50%,并且看起来像这样: 如何使用ArcSegment绘制具有一致半径的半圆的线段
但当arcsegments中的一个具有更然后PI的角度弧度半径不等于所有的方式轮,它看起来像这样:
这里是我写绘制图表的每一段代码:
public Path CreateSlice(Point centerPoint, double radius, ref Point initialPoint, ref double totalAngle, double sliceAngle, Color sliceColor)
{
//A set of connected simple graphics objects that makes up the Slice graphic
Path slicePath = new Path();
slicePath.Fill = new SolidColorBrush(sliceColor);
slicePath.Stroke = new SolidColorBrush(Colors.White);
slicePath.StrokeThickness = 2;
PathGeometry pathGeometry = new PathGeometry();
PathFigureCollection pathFigureCollection = new PathFigureCollection();
PathSegmentCollection sliceSegmentCollection = new PathSegmentCollection();
//The path figure describes the shape in the slicePath object using geometry
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = centerPoint;//Set the start point to the center of the pie chart
//Representing the first line of the slice from the centerpoint to the initial point
//I.E one length of the slice
LineSegment firstLineSegment = new LineSegment();
firstLineSegment.Point = initialPoint;
sliceSegmentCollection.Add(firstLineSegment);
//Calculate the next point along the circle that the slice should arc too.
//This point is calculated using the total angle used of the pie chart including this slice
totalAngle += sliceAngle;
//Calculate the X and Y coordinates of the next point
double x = centerPoint.X + radius * Math.Cos(totalAngle);
double y = centerPoint.Y + radius * Math.Sin(totalAngle);
initialPoint = new Point(x, y);
//Represents the arc segment of the slice
ArcSegment sliceArcSegment = new ArcSegment();
sliceArcSegment.Point = initialPoint;
sliceArcSegment.SweepDirection = SweepDirection.Clockwise;
sliceArcSegment.Size = new Size(radius, radius);
sliceSegmentCollection.Add(sliceArcSegment);
//Representing the second line of the slice from the second point back to the center
LineSegment secondLineSegment = new LineSegment();
secondLineSegment.Point = centerPoint;
sliceSegmentCollection.Add(secondLineSegment);
pathFigure.Segments = sliceSegmentCollection;
pathFigureCollection.Add(pathFigure);
pathGeometry.Figures = pathFigureCollection;
slicePath.Data = pathGeometry;
return slicePath;
}
谁能帮我找出如何绘制arcsegment具有统一半径一路一轮请。