0

カテゴリの円グラフをパーセンテージで表示したいと考えています。

カテゴリのパーセンテージの円グラフを作成するにはどうすればよいですか?

4

4 に答える 4

4

drawRect:メソッドをオーバーライドしてパイを自分で描画するクラスを実装する必要があります。UIBezierPathクラスを使用します。具体的にはaddArcWithCenter:radius:startAngle:endAngle:clockwise:メソッドを調べて、円の一部を描画します。

この記事この記事も参照してください。

于 2011-01-22T07:57:53.683 に答える
3

これを行うための API があります。

  1. MIMチャート
  2. CorePlot効果的だが便利ではないライブラリ。
于 2012-02-17T10:28:16.673 に答える
1

これは、他人のコードのように見える場合、それは私が Web サイトでそれを行う方法を見つけたからであるという警告と、iPhone を起動して間もなくこれを行ったという追加の警告で役立つ場合があります。どのビットが非効率的または間違っているかを教えてくれる人は大歓迎です。私はまだ学んでいます。

static inline float radians(double degrees) { return degrees * M_PI / 180; }

// making a simple pac man shape
- (UIImage*)getImage {

    UIImage* image;
    if(self.completion == 100.0f) {
        image = [UIImage imageNamed:@"completedTaskIcon.png"];
    } else {
        UIGraphicsBeginImageContext(CGSizeMake(SIDELENGTH, SIDELENGTH));

        CGContextRef context = UIGraphicsGetCurrentContext();

        // the image should have a clear background
        [[UIColor clearColor] set];
        CGRect myRect = CGRectMake(0.0f, 0.0f, SIDELENGTH, SIDELENGTH);
        UIRectFill(myRect);

        // color was hopefully set before this method called
        [self.color set];

        // centre point is required
        CGFloat midx = SIDELENGTH/2;
        CGFloat midy = SIDELENGTH/2;
        // radius of the arc
        CGFloat radius = (SIDELENGTH/2) * 0.60f;

        // pie background
        CGContextSetFillColor(context, CGColorGetComponents([[UIColor orangeColor] CGColor]));
        CGContextBeginPath(context);
        CGContextMoveToPoint(context, midx + radius, midy);
        CGContextAddArc(context, midx, midy, radius,  radians(0), radians(360), 0); 
        CGContextFillPath(context); 

        // pie segment
        CGContextSetFillColor(context, CGColorGetComponents([[UIColor blueColor] CGColor]));
        CGContextBeginPath(context);
        CGContextMoveToPoint(context, midx, midy);
        CGContextAddLineToPoint(context, midx + radius, midy);
        CGContextAddArc(context, midx, midy, radius,  radians(0), radians(360 * (self.completion / 100.0f)), 0); 
        CGContextFillPath(context); 
        image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }

    return image;
}
于 2011-01-22T08:09:35.850 に答える
0

他の回答で提案されているライブラリに加えて、私が使用した 2 つの非常に優れたオープン ソースの円グラフ クラスがあります。それらは非常に見栄えがよく、非常にシンプルです。GitHub でそれらを見てください。

于 2012-08-20T10:48:40.863 に答える