创建具有触摸查看值功能的条形图的好策略?
我想创建一个条形图。我已经有一个图表组件,我只需要把它调整为条形图。当触摸其中一栏时,该值会在小视图中弹出。
正如我所看到的,这里可以应用几种不同的策略。我想知道我应该使用哪种策略?其中任何一个或者也许还有其他更好的想法?:
- Bar 是一个 UIButton。
- Bar 是一个支持触摸的 UIImage。
- Bar 是一个 UIView。
- 条形只是绘制的图形,我必须对触摸的坐标进行转码并进行一些计算才能知道哪个条形被触摸。我不是不相信这种策略,但也许您可以为我提供重新思考这一点的理由...
我认为 UILable 是呈现与栏关联的数据的方式?
预先感谢您的建议!
I want to create a bar chart diagram. I already have a diagram component, I just need to adapt it to a bar chart. When touching one of the bars, the value shold pop up in small view.
As I can see there are several different strategies that can be applied here. What I want to know is which strategy should I use? Any of these or perhaps there are other better ideas?:
- Bar is a UIButton.
- Bar is a touch enabled UIImage.
- Bar is a UIView.
- Bar is just painted graphics and I have to transcode the touched coordinates and make some calculations in order to know what bar was touched. I don't don't believe in this strategy but perhaps there are reasons to rethink this that you can provide for me...
I assume that a UILable is the way to present the data associated with the bar?
Thanks in advance for your advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以我的拙见,并且已经写了很多条形图(和其他图表)......#4实际上是性能和我个人偏好的正确选择。在内存中创建虚拟图形以将触摸映射到条形并不困难,因为您只需将矩形存储在数组中并检查点是否位于该矩形内。
现在,话虽如此,如果您想在图表中引入动画,这是非常酷的东西...那么我可以创建一个由多个 UIView 组成的 UIView(每个条形或条形段一个),这样您就可以单独为每个条设置动画,而无需编写自己的动画循环。
只是我的两分钱。
In my humble opinion, and having written many bar charts (and other charts)... #4 is actually the correct choice for performance and my personal preference. Creating the virtual graph in memory to map touches to bars is not difficult at all, as you are simply storing rectangles in arrays and checking to see if points are inside that rect.
Now, having said that, if you want to introduce animations in to your chart, which is pretty cool stuff... then I could create a UIView composed of several UIViews (one for each bar, or bar segment), this way you can animate each bar individually without writing your own animation loop.
just my two cents.
我的想法是#2 和#3 是相同的,因为您使用 UIImageView 显示图像。 UIButton 是 UIView 上的一个非常薄的层,它使事件处理变得容易,但它可能会在视觉上做您不想要的事情(或者也许您想做?)。不管怎样,尝试这些变化都很容易,我只是想尝试一下。我看不出#4 的具体原因,除非你的整体策略推动你朝这个方向发展,就像你开始做一些足够丰富/复杂的绘图,以至于你创建了太多视图。
AFA 弹出显示,这实际上取决于您所说的“弹出”的含义。就像它弹出一样,您是否需要一种方法来消除该弹出窗口?
my thoughts are that #2 and #3 are kind of the same since you'd display an image using a UIImageView. UIButton is a pretty thin layer on UIView that makes the event handling easy, but it might do things visually you don't want (or maybe you do?). Either way, it's so easy to try these variations I'd just play with it. I can't see a specific reason for #4 unless your overall strategy drives you in this direction, like maybe you start doing some drawing that is rich/complex enough that you have too many views being created.
AFA the popup display, it really depends what you mean by "pop up". Like once it pops up, do you need a way to dismiss that popup?
您查看过核心图吗?它是一个活跃且强大的库,非常灵活,应该可以满足您的所有需求。
Have you checked out Core Plot? It is an active and powerful library that is pretty flexible and should meet all your needs.