English 中文(简体)
如何用iphone App 显示配给比例,
原标题:how to show percentage ration with pie chart in iphone app

我正在在iphone app中创建一个饼图表, 它从数组获得4个值, 然后创建饼图, 它显示以不同颜色填满的饼图表, 我也希望它必须显示每个部分的百分比, 比如如果 1 是15%, 15% 35% 和 35% 像这样, 我使用以下代码来创建饼图 。

下面的派级执行

  - (void)drawRect:(CGRect)rect
{

   int c=[itemArray count];

   CGFloat angleArray[c];
   CGFloat offset;
   int sum=0;

   CGContextRef context = UIGraphicsGetCurrentContext();


  CGContextSetAllowsAntialiasing(context, false);
  CGContextSetShouldAntialias(context, false);
   for(int i=0;i<[itemArray count];i++)

    {


    sum+=[[itemArray objectAtIndex:i] intValue];


}


   for(int i=0;i<[itemArray count];i++)

   {

    angleArray[i]=(float)(([[itemArray objectAtIndex:i] intValue])/(float)sum)*(2*3.14); // in radians
    CGContextMoveToPoint(context, radius, radius);
    if(i==0)
        CGContextAddArc(context, radius, radius, radius, 0,angleArray[i], 0);
    else
        CGContextAddArc(context, radius, radius, radius,offset,offset+angleArray[i], 0);
    offset+=angleArray[i];


    CGContextSetFillColorWithColor(context, ((UIColor *)[myColorArray objectAtIndex:i]).CGColor);
    CGContextClosePath(context); 
    CGContextFillPath(context);



    }



   }


   -(void)createGraph{

PieClass *myPieClass=[[PieClass alloc]initWithFrame:CGRectMake(10,440,230,200)];

myPieClass.backgroundColor=[UIColor clearColor];

myPieClass.itemArray=[[NSArray alloc]initWithObjects:valueOne,valueTwo,valueThree,valueFour, nil];

myPieClass.myColorArray=[[NSArray alloc]initWithObjects:[UIColor blueColor],[UIColor redColor],[UIColor greenColor],[UIColor brownColor], nil];

myPieClass.radius=100;

[self.view addSubview:myPieClass];

}
最佳回答

< a href=" "https://github.com/honcheng/iOSPlot" rel="no follow"。 这将帮助您使用% 比例显示的派图源代码链接 。 这将帮助您 。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签