2014-10-17 63 views
2

我想通過Y軸繪製自定義標籤和網格線, 如果我設置標籤策略CPTAxisLabelingPolicyNone,並將自定義標籤添加到Y軸,我可以在Y軸上繪製所需的標籤。核心情節:是否「setLabelingPolicy:CPTAxisLabelingPolicyNone」和「setMajorGridLineStyle:majorGridLineStyle」相互排斥?

[yAxis setLabelingPolicy:CPTAxisLabelingPolicyNone]; 

但是我無法獲得網格線的工作。

[yAxis setMajorGridLineStyle:majorGridLineStyle]; 

如果我刪除標籤策略無,那麼我可以得到網格線。

想知道什麼是解決方案?

代碼設置Y軸標籤:

NSMutableArray *yLabels = [NSMutableArray arrayWithObjects:@"None", @"Awake", @"Light",@"Middle",@"Deep", nil]; 
NSMutableArray *customLabelsY = [NSMutableArray arrayWithCapacity:[yLabels count]]; 
for (int loc=1; loc <= 4; loc++) 
{ 
    CPTAxisLabel *newLabelY = [[CPTAxisLabel alloc] initWithText: [yLabels objectAtIndex:loc] textStyle:textStyle]; 
    newLabelY.tickLocation = [[NSDecimalNumber numberWithInt:loc] decimalValue]; 
    newLabelY.offset = yAxis.labelOffset + yAxis.majorTickLength; 
    [customLabelsY addObject:newLabelY]; 
} 
[yAxis setAxisLabels:[NSSet setWithArray:customLabelsY]]; 

回答

2

隨着CPTAxisLabelingPolicyNone,您的應用程序必須提供刻度位置(主要和/或次要的),如果你想刻度線和/或網格線。它們與標籤無關,因此您可以在創建標籤時標記沒有刻度標記的位置和/或跳過某些標記位置。


編輯:位置創建標籤,並設置majorTickLocations完成後,當

跟蹤。

NSMutableSet *locations = [NSMutableSet set]; 

for (int loc=1; loc <= 4; loc++) { 
    // create labels 

    [locations addObject:@(loc)]; 
} 

yAxis.majorTickLocations = locations; 
+0

感謝您的回答。回覆晚了非常抱歉。我發佈瞭如何設置標籤。請檢查我的代碼。問題依然存在,正如原來的問題所解釋的那樣。 – brbabu 2014-10-28 23:07:23