Bar Graphs in iOS app [closed]

depends on what you really want. If you just need a bunch of ugly bars core-plot might be a bit too much for you.

It takes this much code to implement a bargraph. I think this is like half the code you would need for core-plot datasources. And even a nice implementation will take less time than integrating core-plot into your project.
Core-plot is a big fat monster. Like all those "I can do everything you want"-frameworks.

- (void)drawRect:(CGRect)rect {
    CGFloat height = self.bounds.size.height;
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);
    CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor);
    CGFloat barWidth = 30;
    int count = 0;
    for (NSNumber *num in values) {
        CGFloat x = count * (barWidth + 10);
        CGRect barRect = CGRectMake(x, height - ([num floatValue] * height), barWidth, [num floatValue] * height);
        CGContextAddRect(context, barRect);
        count++;
    }
    CGContextFillPath(context);
}

Use this buddy. :)

EDIT

Installing Core Plot might be some headache for you, if you need help in that, let me know.

If you need very simple graphs you can go for ECGraph


You can check out the PowerPlot library. It is a powerful choice for native charts on iOS, here are a two sample bar graphs:

Bar chart - German Federal Election 2009Bar chart - Web traffic

Using PowerPlot, the code needed to generate these two graphs is available here (upper chart) and here (lower chart).


There are several commercial tools for iOS charting, all of which can render bar graphs:

  • ShinobiControls - which has many interactive features as shown in this video.
  • www.threedgraphics.com
  • iPhone Charting Library for iPhone Objective-C
  • NChart3D (supports bars in 2D and 3D)

Full Disclosure - I work for Scott Logic, which is the parent company of ShinobiControls