Alex Reynolds
Alex Reynolds

Reputation: 96967

How to correctly add Core Plot label/annotation to a CPPieChart object?

I am testing a CPPieChart and finding that the data source delegate method -sliceLabelForPieChart:recordIndex: is not displaying a slice label.

In addition, there is no title property for the pie chart type.

So I figured I would test using a UILabel instance:

UILabel *viewTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 24.0f)];
viewTitle.text = @"Total Space";
[hostingView addSubview:viewTitle];
[viewTitle release];

Interestingly, it looks like the label coordinates are inverted and the text is mirrored:

alt text

What is the best way to resolve the coordinate system inversion and text mirroring?

Upvotes: 0

Views: 2643

Answers (2)

Eric Skroch
Eric Skroch

Reputation: 27381

Slice labels are not implemented--that delegate method exists to define the interface, but is not used yet.

We recently added the ability to add titles to the graph but not individual plots. The iPhone version of CPTestApp adds a title to the bar chart to show how it's done.

Upvotes: 0

Brad Larson
Brad Larson

Reputation: 170317

Sorry about that. At some point, I need to finish the implementation of that chart type.

The reason the UILabel is being flipped is that we host the Core Plot graphs within a UIView that inverts its layer's coordinate system. This is done to preserve the same coordinate system between Mac and iPhone for the framework (based on the normal Quartz coordinate system where 0,0 is the bottom left).

Instead of adding a UILabel to the graph, you could directly add a CPTextLayer to the graph layer (or one of the other layers in the display hierarchy). CPTextLayers play within the standard coordinate space of the Core Plot graphs, so they should render properly.

Upvotes: 2

Related Questions