views:

262

answers:

2

Hello,

I want to add a title to my graph that gives a short description or name about the plot. For example, I have a table with a list of products and my graph shows how much those products cost. There should be a label/annotation superimposed on the graph that gives the name of the product.

A: 

Create a UILabel, set it's text, and add it as a subview of the graph view.

Jasarien
Actually, you don't want to set it as a subview, because we invert the coordinate space of things drawn within the graph. Setting it as a sibling view that is positioned above the graph should do the trick.
Brad Larson
Fair enough, sounds reasonable.
Jasarien
A: 

Brad -- siblings inside of which type of View exactly? In the CPTestApp, I took the BarChart NIB and placed both the CPLayerHostingView and a UILabel (for the Plot title) into a generic UIView (making them children of the UIView). The graph showed up, but the label did not. How do I get the label to show?

EDIT: I figured it out with this line -- in CPTestAPP, change

CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view; to

CPLayerHostingView *hostingView = (CPLayerHostingView *)layerView;

where layerView is your UIView (with class CPLayerHostingView -- make sure to set this in IB) that is contained inside of a generic UIView. That generic UIView can have all the UILabels you want as children. woohoo!

Graph with label here:

http://www.freeimagehosting.net/image.php?80ef43717f.png

Fed Rodriguez