Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi, I'm also attempting, 15 years later, to draw a pie chart, and also having problems with curveTo. I'm not sure if the current curveTo is improved or not, but when I try to connect the sides of the slice with an arc, from the start angle to the end angle, with slices defined as an array of percentages totalling 100, I get a concave curve rather than an arc of the specified radius with this code:
var startAngle:Number = -90;
for (var i:int = 0; i < slices.length; i++) {
var sliceAngle:Number = slices[i] / 100 * 360;
var endAngle:Number = startAngle + sliceAngle;
var startRadians:Number = startAngle * Math.PI / 180;
var endRadians:Number = endAngle * Math.PI / 180;
pieChart.graphics.beginFill(getRandomColor());
pieChart.graphics.moveTo(originX, originY);
pieChart.graphics.lineTo(originX + Math.cos(startRadians) * radius, originY + Math.sin(startRadians) * radius);
pieChart.graphics.curveTo(originX, originY, originX + Math.cos(endRadians) * radius, originY + Math.sin(endRadians) * radius);
pieChart.graphics.lineTo(originX, originY);
pieChart.graphics.endFill();
startAngle = endAngle;
}
Do I not have the correct argument for curveTo?
Copy link to clipboard
Copied
your control points are originX,originY so that's probably exactly what you do not want. though again, using lineTo is much easier to control.
Copy link to clipboard
Copied
Yes, misunderstood the arguments for curveTo. Understand now that it's a quadratic Bezier, starting from the current point, just needing a single control point and the last anchor point. Unusual that there's a function for that kind of curve, but no simple arcTo function, also starting from the current point, just needing the origin, radius and endpoint. Solved with multiple line segments. Thanks.
Copy link to clipboard
Copied
an arcTo (ie, curveTo) function is always going to need, at least, one control point because there are many ways to arc from A to B.