rajeev karamchedu

Technology and Professional Services Director, currently part of a very exciting and talented team of technology/data management solution provider, IronBrick

20 responses to “Drawing Pie Charts using iPhone SDK”

  1. cak

    This doesn’t work, where is snapshot_start defined? Have you even tried to run this? If you have, you are missing something out.

  2. Bob Donahue

    I’m trying to find a general data plotting library for the iPhone.

    Seems weird that I’d have to develop it from scratch, just to do a simple X,Y scatter plot or a bar graph.

    Are you aware of any existing packages?

    Thanks in advance,
    Bob

  3. Vinayak

    Hi,
    when i run this code got blank white screen only. can you please submit the steps how to execute this code from begin in short.

    just like

    1. select window base application
    2. add GraphView.h and GraphView.m

    .
    .
    . finish

    like this.

  4. Vinayak

    Hi Rajeev ,
    I desperately need pie chart code. Please help me out.

  5. mike

    why are you defining PI on line 3 if you can use the constant M_PI?

  6. iphone architect

    thanks for the excelent post, need to integrate into my app

  7. Howto: Drawing Pie Charts using iPhone SDK | Iphone Development Exchange

    [...] Drawing Pie Charts using iPhone SDK [...]

  8. Top 15 Must-Have iPhone SDK Tutorials with source code | Iphone Development Exchange

    [...] Learn how to draw Pie Charts using the latest iPhone [...]

  9. adam m

    this example worked great ! To make it work out of the box, replace the CGxxxx stuff at the bottom with this: It just uses the pie1_start, and the pie1_finish.

    CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor greenColor] CGColor]));
    CGContextMoveToPoint(ctx, x+2*offset, y);
    CGContextAddArc(ctx, x+2*offset, y, 100, radians(0), radians(0), 0);
    CGContextClosePath(ctx);
    CGContextFillPath(ctx);

    // system capacity
    CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:15 green:165/255 blue:0 alpha:1 ] CGColor]));
    CGContextMoveToPoint(ctx, x+offset,y);
    CGContextAddArc(ctx, x+offset, y, 100, radians(pie1_start), radians(pie1_finish), 0);
    CGContextClosePath(ctx);
    CGContextFillPath(ctx);

    /* data capacity */
    CGContextSetFillColor(ctx, CGColorGetComponents( [[UIColor colorWithRed:99/255 green:184/255 blue:255/255 alpha:1 ] CGColor]));
    CGContextMoveToPoint(ctx, x, y);
    CGContextAddArc(ctx, x, y, 100, radians(pie1_finish), radians(pie1_start), 0);
    CGContextClosePath(ctx);
    CGContextFillPath(ctx);

    to add it to your main window just put these lines in Your’AppDelegate.m’

    GraphView *graph = [[GraphView alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 460.0)];
    [window addSubview:graph];

  10. Sohel Taslim

    It works for me without any problem. Nice documentation.
    Thanks for the work.
    I am looking for more better resource. Your code will help me to build my expected one.

  11. J2Lite

    Core Plot framework provides a better way to create Pie Charts. You can use even custom gradients for shading the Pie Slices. This tutorial will show you how Core Plot can be used to build Pie Charts in iPhone.

  12. Dave Janssen

    Thanks for the post. I tried using core-plot, but is doesn’t seem to allow you to add labels to slices in a pie chart, at least not at the moment. So I will use Quartz for the time being.

  13. plusz

    Nice tutorial. I made something much more sophisticated. 3D charts with user interaction available :)

    there is new, nice Pie Chart 3D library. 3D charts which you can rotate and scale with fingers + protocol for getting information about tapped slice

    http://iphone.orpi.pl/?p=20

  14. Naren

    Hi Rajeev,
    Thanks for the code,
    rendering of pie chart is ok but can you give me an idea of how to identify the touch event on different pie slices. if you know a way please help me out regarding this.

    With Thanks
    Naren Mudgal

  15. Brad

    Well…this piece of code is definetly quite strange…

    where does the red color come from? I changed every value, but it stays always red…The blue color can be changed. The red not.

  16. Renuga

    For me error coming in this line.

    CGRect parentViewBounds = self.bounds;

    error:request for member ‘bounds’ in something not a structure or union

    Exactly I want to draw a pie chart in my iphone application…Help me out to do this….

Leave a Reply