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!
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.