iOS 应用程序中的条形图

发布于 2024-10-20 01:06:14 字数 1539 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

游魂 2024-10-27 01:06:14

取决于你真正想要什么。如果你只需要一堆丑陋的条形,核心情节对你来说可能有点太多了。

实现条形图需要这么多代码。我认为这相当于核心图数据源所需代码的一半。即使是一个很好的实现,也比将 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);
}

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);
}
随心而道 2024-10-27 01:06:14

使用这个好友。 :)

编辑

安装 Core Plot 可能会让您有些头疼,如果您需要帮助,请告诉我。

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

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

虫児飞 2024-10-27 01:06:14

您可以查看 PowerPlot 库。它是 iOS 上原生图表的强大选择,这里有两个示例条形图:

条形图 - 德国联邦选举 2009
条形图 - Web 流量

使用 PowerPlot,可以使用生成这两个图表所需的代码 此处(上图)此处(下图)

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 2009
Bar chart - Web traffic

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

吾家有女初长成 2024-10-27 01:06:14

有几种用于 iOS 图表的商业工具,所有这些工具都可以呈现条形图:

全面披露 - 我在 Scott Logic 工作,该公司是 ShinobiControls 的母公司

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

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

想你只要分分秒秒 2024-10-27 01:06:14

请参阅 Raywenderlich 核心图教程,它将帮助您了解 core-plot 以及如何使用它创建各种类型的图表。
同样的链接是
http://www.raywenderlich.com /13271/how-to-draw-graphs-with-core-plot-part-2

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

兲鉂ぱ嘚淚 2024-10-27 01:06:14

CorePlot 是 iOS 中最好的图形绘制库。以下是一些屏幕截图示例,介绍您可以使用它创建的内容。

如果您想在不使用外部库的情况下完成此操作,您可以使用 Core Graphics 等低级绘图框架进行绘制。 Apple 有关自定义绘图的文档位于此处

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.

娇俏 2024-10-27 01:06:14

我已经困惑这个问题有一段时间了。在许多情况下,子视图可以发挥作用。只需使用代数即可,瞧,大小正好。

对于大型函数,您可能希望避免视图,并深入研究绘制函数,然后使用代数

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

输什么也不输骨气 2024-10-27 01:06:14

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文