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

  • SEARCH
  • Home
  • 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 7865857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:12:43+00:00 2026-06-03T00:12:43+00:00

I have Created a PieChart Using the following Code. Here, I Have taken the

  • 0

I have Created a PieChart Using the following Code. Here, I Have taken the sum of x and y as 100% to display the x% as red color and y% as green color on pieChart.

On the red color i want to display the exact x% (Example 45% (or) 55%) and on the green color i want to display the exact y% (Example 55% (or) 45%).

In my application the X and Y values are Variables. Those Values are changing each time when i run my application. I want to display the pieChart with green and red colors with the percentage on those regions. How Can i make frames to display percentages on that regions?

.m file

- (void)drawRect:(CGRect)rect
{
// Drawing code

 int x = 25;
 int y = 42;

 float sum = x + y;
 float mult = (360/sum);

 float startDeg = 0;
 float endDeg = 0;

 int x = 74;
 int y = 60;
 int r = 60;

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

 startDeg = 0;
 endDeg = (x * mult);
 if(startDeg != endDeg)
 {
 CGContextSetRGBFillColor(ctx, 0.0, 0.8, 0.0, 1.0);
 CGContextMoveToPoint(ctx, x, y);
 CGContextAddArc(ctx, x, y, r, (startDeg)*M_PI/180.0, (endDeg)*M_PI/180.0, 0);
 CGContextClosePath(ctx);
 CGContextFillPath(ctx);
 }

 startDeg = endDeg;
 endDeg = endDeg + (y * mult);
 if(startDeg != endDeg)
 {
 CGContextSetRGBFillColor(ctx, 0.8, 0.0, 0.0, 1.0);
 CGContextMoveToPoint(ctx, x, y);
 CGContextAddArc(ctx, x, y, r, (startDeg)*M_PI/180.0, (endDeg)*M_PI/180.0, 0);
 CGContextClosePath(ctx);
 CGContextFillPath(ctx);
 }
}
  • 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-06-03T00:12:44+00:00Added an answer on June 3, 2026 at 12:12 am

    You can draw a string with NSString drawInRect during the drawRect method. For example:

    [percentageString drawInRect:CGRectMake(100, 100, 30, 20) 
                        withFont:font 
                   lineBreakMode:UILineBreakModeClip 
                       alignment:UITextAlignmentLeft];
    

    Update

    Here is how to find the x, y for placing text:

    CGFloat startDegree = 180;                             // start at 180
    CGFloat endDegree = degree;                            // end at some value
    
    CGFloat mid = (endDegree + startDegree) / 2;           // find midpoint
    CGFloat rad = DEGREES_TO_RADIANS(mid);                 // convert to radians
    
    
    // center is center of pie chart
    // radius is how big the pie chart is
    // 30 is extra to draw text outside circle
    
    CGFloat x =  center.x + ((radius + 30) * cos(rad));    
    CGFloat y = center.y + ((radius + 30) * sin(rad));
    
    NSLog(@"X Y: %f %f %f", x, y, degree);
    
    NSString *text = @"Test";   
    [text drawInRect:CGRectMake(x, y, 50, 44) withFont:[UIFont systemFontOfSize:14.0f]];
    

    I had a sample pie chart so I used that. It has a slider with degrees. In the example, I can draw a segment of the pie chart from 180 degrees to 360 degrees.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm prototyping a chart using ASP.NET Chart Controls. I have the following code to
I have a pie chart created by graphael this.element = this.raphHolder.piechart(100, 100, 100, data,{legend
I have created a mac application using the WebView. But issue is that webView
I have created a currency fomatter class. I want this to be a util
I have created a Layout using ExtJs. It consists of a left menu and
I have created a SSRS 2008 report.I have created a matrix.I want to make
I have created a triangle using canvas but i was wondering if there was
I have created a smalldatetime field. I am using a dbml file to access
I have created a cookie using php and now I need to create a
I have created infopath form library in SharePoint sever2010. I am using Windows server

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.