Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bar Graphs in iOS app [closed]

Tags:

graph

ios

I want to plot a bar-graph in my application. How should I do it exactly ?(I have no idea in Graphs). Please suggest some steps to start with and go on.

Thanks

like image 639
Akshay Avatar asked Mar 02 '11 07:03

Akshay


1 Answers

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);
}
like image 180
Matthias Bauch Avatar answered Nov 02 '22 07:11

Matthias Bauch