English 中文(简体)
• 如何展示PieChart文本?
原标题:How to display Text on a PieChart?

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.

欲显示准确的<条码>x% (Example 45%/code>(or)55%)和绿色颜色(希望显示准确的y% (Example 55% (or)45%)。

在我的申请中,<代码>XY数值为可变数值。 这些价值在我提出申请时每改变一次。 我想用绿色和红色显示这些区域的百分比。 如何制定在这些地区显示百分比的框架?

.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);
 }
}
最佳回答

您可以在参考法中选取国家抽样数据。 例如:

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

<>Update>

这里指的是如何找到该x,以及放在案文上:

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.

问题回答

暂无回答




相关问题
Which non-bold UTF-8 iPhone SDK font can I use here?

Problem: I create a UILabel with this font: label.font = [UIFont systemFontOfSize:15.0f]; Now this system font is bold, but I want to display pretty small text, and the text may also contain very ...

Limiting file upload type

Simple question. Is there a way to only allow txt files upon uploading? I ve looked around and all I find is text/php, which allows PHP. $uploaded_type=="text/php

Extract everything from PDF [closed]

Looking for solution to extract content from a PDF file (using console tool or a library). It will be used on server to produce on-line e-books from uploaded PDF files. Need to extract following ...

Flash & external form fields

Does anybody know if this is possible? I am trying to create a flash movie that will show / preview what I am typing into a field in a normal HTML form. The call to update the flash movie would most ...

Avoiding escape sequence processing in ActionScript?

I need to mimic C# functionality of the @ symbol when it precedes a string. @"C:AFilePath" for example What is the best way to do this? Also there are some sites that will escape larger ...

iPhone: Draw rotated text?

I want to draw some text in a view, rotated 90°. I m pretty new to iPhone development, and poking around the web reveals a number of different solutions. I ve tried a few and usually end up with my ...

Numbering in jQuery

How could I change the text below so that the text within it has a number appended to it. <div class="right">This is some text</div> <div class="right">This is some text</div>...

热门标签