iOS 应用中的条形图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5164523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bar Graphs in iOS app
提问by Akshay
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
谢谢
采纳答案by Vaibhav Tekam
回答by Matthias Bauch
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.
取决于你真正想要什么。如果您只需要一堆丑陋的条形,那么 core-plot 对您来说可能有点太多了。
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.
实现条形图需要这么多代码。我认为这就像核心绘图数据源所需的代码的一半。即使是一个很好的实现也比将 core-plot 集成到您的项目中花费的时间更少。
核心情节是一个大胖怪物。就像所有那些“我可以做你想做的一切”的框架一样。
- (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);
}
回答by user8472
You can check out the PowerPlot library. It is a powerful choice for native charts on iOS, here are a two sample bar graphs:
您可以查看PowerPlot 库。它是 iOS 上原生图表的强大选择,这里有两个示例条形图:
Using PowerPlot, the code needed to generate these two graphs is available here (upper chart)and here (lower chart).
回答by ColinE
There are several commercial tools for iOS charting, all of which can render bar graphs:
有几个用于iOS图表的商业工具,都可以渲染条形图:
- 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)
- ShinobiControls- 如本视频所示,它具有许多交互功能。
- www.threedgraphics.com
- 用于 iPhone Objective-C 的 iPhone 图表库
- NChart3D(支持 2D 和 3D 条形)
Full Disclosure- I work for Scott Logic, which is the parent company of ShinobiControls
完全披露- 我为 ShinobiControls 的母公司 Scott Logic 工作
回答by user1548843
Refer Raywenderlich core plot tutorial it would help you lot to understand core-plotand 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
请参阅Raywenderlich核心情节的教程,这将有助于你很多了解核心地块使用它,以及如何箱各类型的图表。相同的链接是 http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2
回答by Krishnabhadra
CorePlotis the best Graph plotting library in iOS. Here are some screenshot exampleson what you can create with it.
CorePlot是 iOS 中最好的图形绘图库。以下是一些有关您可以使用它创建的内容的屏幕截图示例。
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.
如果你想在不使用外部库的情况下完成它,你可以使用像 Core graphics 这样的低级绘图框架来绘制它。Apple 关于自定义绘图的文档在这里。
回答by Vinícius Rodrigues
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 :)
这个第三方项目对我来说效果很好,我发现它的设计比大多数其他项目要好得多。不幸的是支付,但它总是一个选择:)
回答by Stephen J
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
对于大的,您可能希望避免使用视图,并深入了解绘图函数,然后使用代数