Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:03:05+00:00 2026-05-25T22:03:05+00:00

I am trying to create a pie chart. Each pie should be with different

  • 0

I am trying to create a pie chart. Each pie should be with different color and have it’s border. So I made my own class PieChart.m:

#import "PieChart.h"


@implementation PieChart
@synthesize startDeg, endDeg, isSelected, colorNumber;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code

    int centerX = 120;
    int centerY = 160;
    int radius  = 94;

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(ctx, 255.0/255.0, 255.0/255.0, 255.0/255.0, 1.0);
    CGContextSetLineWidth(ctx, 2.0);

    CGContextSetRGBFillColor(ctx, [self getColorFor:1]/255.0, [self getColorFor:2]/255.0, [self getColorFor:3]/255.0, 1.0);

    CGContextMoveToPoint(ctx, centerX, centerY);
    CGContextAddArc(ctx, centerX, centerY, radius, (startDeg)*M_PI/180.0, (endDeg)*M_PI/180.0, 0); 

    CGContextClosePath(ctx);
    CGContextFillPath(ctx);
}

- (void)dealloc
{
    [super dealloc];
}

-(float)getColorFor:(int)rgb {
    if (colorNumber == 1) {
        switch (rgb) {
            case 1:
                return 232.0;
                break;
            case 2:
                return 96.0;
                break;
            case 3:
                return 104.0;
                break;

            default:
                return 255.0;
                break;
        }
    }
    if (colorNumber == 2) {
        switch (rgb) {
            case 1:
                return 248.0;
                break;
            case 2:
                return 198.0;
                break;
            case 3:
                return 6.0;
                break;

            default:
                return 255.0;
                break;
        }
    }

    return 255.0;
}

@end

The problem is that the borders would never draw. Or if I manage to draw the border the fill wouldn’t be there! Any suggestions how this should be achieved?

Here is how I use the class in my viewcontroller:

- (void)viewDidLoad
{
    [super viewDidLoad];

    PieChart *pie1 = [[PieChart alloc] initWithFrame:CGRectMake(10, 10, 300, 400)];
    pie1.startDeg = 0;
    pie1.endDeg = 127;
    pie1.colorNumber = 1;
    pie1.backgroundColor = [UIColor clearColor];

    PieChart *pie2 = [[PieChart alloc] initWithFrame:CGRectMake(10, 10, 300, 400)];
    pie2.startDeg = 127;
    pie2.endDeg = 360;
    pie2.colorNumber = 2;
    pie2.backgroundColor = [UIColor clearColor];

    [self.view addSubview:pie1];
    [self.view addSubview:pie2];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:03:06+00:00Added an answer on May 25, 2026 at 10:03 pm

    The problem with your code is that you only fill your path, not stroking it – so naturally border is now drawn. You need to replace CGContextFillPath call with

    CGContextDrawPath (ctx, kCGPathFillStroke);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a symmetrical pie-chart with 6 pieces of 60 degrees each
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
Hi I am trying to create a simple pie chart using the HTML canvas
I am trying to create a pie chart and am customizing the example here:
HI im trying to create simple pie chart using the MS Chart controls. When
I am trying to create a simple and animated pie chart using CAShapeLayer .
I am trying to create a spinning wheel with text on it. I have
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I trying create a class derivated from System.Web.UI.Page and in override Render i set
I'm trying create a gantt chart with highcharts and I need to put the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.