Bar Graphs in iOS app [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this questionI 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
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:
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
Refer Raywenderlich core plot tutorial it would help you lot to understand core-plot and how to crate various type of graph using it. linke for the same is http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2
CorePlot is the best Graph plotting library in iOS. Here are some screenshot examples on what you can create with it.
If you want to do it without using external libraries, you can draw it using low level drawing framework like Core graphics. Apple's documentation regarding custom drawing is here.
I've been puzzling this for awhile now. In many cases, subviews will work. Just use algebra and voila, sized just fine.
For large ones, you might want to avoid views, and go deeper into the draw functions, then use algebra
This third party project worked nice for me and I found the design much better than most other projects. Unfortunately is paid, but it's always an option :)
http://www.binpress.com/app/ios-bar-chart-view/1836
精彩评论