2012-09-11 52 views
2

我有一個核心陰謀的問題,這導致我的悲痛,並在互聯網上搜索找不到解決方案。我擔心這是一個非常簡單的監督,但對於我的生活,我無法弄清楚它是什麼。如何在Core Plot中使用多個自定義標籤?

本質上,當我在覈心繪圖中設置自定義標籤時,即使相關數組填充了正確的數據(如刻度位置和標籤),也只有一個標籤出現在刻度位置零處。

我旁路自定義標籤例程通過手動輸入到newLabels到customLabels數組中,這工作,所以我害怕我缺少某些地方的例程中的基本東西。

NSUInteger labelLocation = 0; 
NSMutableArray *customLabels = [[NSMutableArray alloc] initWithCapacity:[self.days count]]; 


for (NSNumber *tickLocation in self.customTickLocations) 
{ 

    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[self.dateLabels objectAtIndex:labelLocation] textStyle:axisTextStyle]; 
newLabel.tickLocation = [tickLocation decimalValue]; 
    int i = [tickLocation intValue]; 

    newLabel.offset = 5.0f; 
    newLabel.rotation = M_PI/4; 

    [customLabels addObject:newLabel]; 
    NSLog(@"Label is %@", [self.dateLabels objectAtIndex:labelLocation]); 

    labelLocation = labelLocation + 1; 


    NSLog(@"Tick Location is %i", i); 
} 
NSLog(@"Number of labels is %i", [customLabels count]); 

axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels]; 
axisSet.xAxis.majorTickLocations = [NSSet setWithArray:self.customTickLocations]; 

NSLog(@"I have set customlabels"); 

這是我的日誌:

2012年9月11日10:39:23.725 SnoozeBaby [12000:C07] Label是九月11

2012年9月11日10時39分:23.725 SnoozeBaby [12000:C07]蜱位置是0

2012年9月11日10:39:23.725 SnoozeBaby [12000:C07] Label是九月10

2012年9月11日10:39:23.726 SnoozeBaby [ 12000:C07]蜱位置是150

2012年9月11日10:39:23.726 SnoozeBaby [12000:C07]標籤的數目是2

2012年9月11日10:39:23.728 SnoozeBaby [12000 :c07]我已經設置了自定義標籤

回答

1

您是否將CPTAxis標籤策略設置爲CPTAxisLabelingPolicyNone?除非你這樣做,否則你將無法看到標籤。

要注意的第二件事是,您不會釋放每個迭代創建的每個CPTAxisLabel對象。

我沒有測試過這一點,但我要說的是,你應該先設置的位置,然後將標籤:

axisSet.xAxis.majorTickLocations = [NSSet setWithArray:self.customTickLocations]; 
axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels]; 
+1

非常感謝薩爾瓦多開發。我確實有CPTAxisLabelingPolicyNone,我應該事後看到更多的代碼。我的問題原來是我使用CGFloat變量爲plotSpace.XRange設置了一個xMax範圍,但是傳遞了[fetchResults count],當然這是一個int,所以xMax將它自己設置爲零。我錯過了,因爲編譯器沒有發出警告。感謝您花時間幫忙! – user1662478

相關問題