0

我正在开发一个包含饼图的应用程序。我想显示要显示在中心对应区域的值(用于制作饼图)。

我正在使用此代码绘制饼图:

  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);

我可以在饼图顶部添加标签,但无法将标签放置在区域的中心。

4

2 回答 2

1

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);
于 2010-07-29T21:47:50.490 回答
0

显示饼图的标签需要一点数学知识。HUChart是绘制半饼图,但我想你会在那里找到一些有用的信息。

于 2013-11-25T00:33:31.897 回答