2012-11-20 44 views
4

我試圖在Core-Plot中更改條形圖中標籤的默認位置。 我使用這種方法:CPTBarPlot(Core-Plot)上的定位標籤

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

我回:

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

我得到這樣的結果:

enter image description here

但我想顯示如下:

enter image description here

有什麼想法嗎?我試圖找到關於文檔的答案,但我一直不可能。

回答

9

對條形圖使用負面labelOffset。默認值是+10,將標籤放在條上方10個像素處。該屬性從CPTPlot繼承,因此它適用於所有繪圖類型,但默認值和行爲有所不同。

+0

感謝您的回答! – mhergon

+0

@Eric Skroch有什麼方法可以在plot中設置不同的cptbarplots labelOffset?我想在CPTBarplot的中心顯示標籤。 –

+2

@HinataHyuga否。不是數據標籤,而是使用以「CPTTextLayer」作爲其內容的情節空間註釋並將其居中在條上。 –