4

I am trying to change default position of labels in Bar chart with Core-Plot. I am using this method:

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)idx;

And I return:

return textLayer = [[CPTTextLayer alloc] initWithText:@"2222" style:textStyle];

I get this result:

enter image description here

But I want to appear as follows:

enter image description here

Any idea? I tried to find answer on documentation, but I has been impossible.

iDev
  • 23,310
  • 7
  • 60
  • 85
mhergon
  • 1,688
  • 1
  • 18
  • 39

1 Answers1

9

Use a negative labelOffset for the bar plot. The default is +10 which puts the labels 10 pixels above the bars. This property is inherited from CPTPlot so it works for all plot types, although the default value and behavior varies somewhat.

Eric Skroch
  • 27,381
  • 3
  • 29
  • 36
  • @Eric Skroch Is there any way to set different labelOffset of cptbarplots in a plot? I want to show label exactly in the center of CPTBarplot. – Baby Groot Jun 06 '13 at 10:07
  • 3
    @HinataHyuga No. Instead of data labels, use a plot space annotation with a `CPTTextLayer` as its content and center it on the bar. – Eric Skroch Jun 06 '13 at 13:24
  • @EricSkroch is there a way to have it so that its at the axis end and not the tip of the bar end? – Sam Jarman Jan 14 '14 at 04:27