views:

90

answers:

1

Hi,

I am developing an application that has a Pie Chart in it. I want to display the values(used for making the pie chart) to be displayed in the center corresponding area.

I am using this code to draw the PieChart:

  CGContextSetRGBFillColor(ctx, 0.52, 0.63, 0.31, 1.0);
  CGContextMoveToPoint(ctx, posX, posY);
  CGContextAddArc(ctx, posX, posY, r,(startDeg)*M_PI/180.0, (endDeg)*M_PI/180.0, 0);
  CGContextClosePath(ctx);
  CGContextFillPath(ctx);

I can add the labels on top of pie chart but I am not able to position the label in the center of the area.

Can anyone please help me with this issue. Its very urgent and important. I have spent a lot of time on this issue...

Thank you

A: 

The "center" of the area is sort of a poorly defined concept when you're talking about a pie slice. Here's what I would do:

Take an angle halfway between startDeg and endDeg along with a radius about 1/2 to 2/3 of r and plop the center of your label there. A polar to rect coordinate conversion is necessary, which if you have forgotten is:

x = r * cos(angle);
y = r * sin(angle);
Jason Foreman