The core functions are: Cgcontextaddarc (cgcontextref C, CGFloat x, cgfloat y, cgfloat radius, cgfloat startangle, cgfloat endangle, int cloc kwise) * Cgcontextref: Graphics context * x, y: Start drawing coordinates * Radius: RADIUS * startangle, Endangle: Start Radian, End Radian * Clockwise: direction of painting (clockwise, counterclockwise) with this A function can draw any fan, so the pie chart is no longer spoken. #define PI 3.14159265358979323846#define radius 100static inline float radians (double degrees) { return degrees * PI/180; }static inline void DrawArc (Cgcontextref ctx, Cgpoint point, float angle_start, float angle_end, uicolor* color) {Cgconte Xtmovetopoint (CTX, Point.x, POINT.Y); Cgcontextsetfillcolor (CTX, cgcolorgetcomponents ([color Cgcolor])); Cgcontextaddarc (CTX, Point.x, Point.y, radius, Angle_start, angle_end, 0); Cgcontextclosepath (CTX); Cgcontextfillpath (CTX); }-(void) DrawRect: (cgrect) rect {cgcontextref CTX = Uigraphicsgetcurrentcontext (); Cgcontextclearrect (CTX, rect); float Angle_start = radians (0.0); float angle_end = radians (121.0); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Yellowcolor]);Angle_start = Angle_end; Angle_end = radians (228.0); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Greencolor]); Angle_start = Angle_end; Angle_end = radians (260); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Orangecolor]); Angle_start = Angle_end; Angle_end = radians (360); DrawArc (CTX, Self.center, Angle_start, Angle_end, [Uicolor Purplecolor]);}
IPhone uses CG API to draw a pie chart (pie chart)