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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:05:23  来源:igfitidea点击:

Bar Graphs in iOS app

iosgraph

提问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

Use thisbuddy. :)

使用这个伙伴。:)

EDIT

编辑

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

安装 Core Plot 可能会让您头疼,如果您需要这方面的帮助,请告诉我。

If you need very simple graphs you can go for ECGraph

如果您需要非常简单的图表,您可以选择ECGraph

回答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 上原生图表的强大选择,这里有两个示例条形图:

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

条形图 - 2009 年德国联邦选举条形图 - 网络流量

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

使用PowerPlot,以生成这两个图所需要的代码是可用在这里(上图)这里(下图)

回答by ColinE

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

有几个用于iOS图表的商业工具,都可以渲染条形图:

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 :)

这个第三方项目对我来说效果很好,我发现它的设计比大多数其他项目要好得多。不幸的是支付,但它总是一个选择:)

http://www.binpress.com/app/ios-bar-chart-view/1836

http://www.binpress.com/app/ios-bar-chart-view/1836

回答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

对于大的,您可能希望避免使用视图,并深入了解绘图函数,然后使用代数