2012-05-25 47 views
1

爲什麼labelingPolicy不同CPTAxisLabelingPolicyNone的字符串標籤鴕鳥政策發現???CorePlot:與labelingPolicy衝突x軸文本標籤

x.labelingPolicy = CPTAxisLabelingPolicyNone; 

enter image description here

我想這GRIDLineStyle,但我的文字標籤:

x.labelingPolicy = CPTAxisLabelingPolicyFixedInterval 

enter image description here

我完全xAxisLabels與此代碼:

NSMutableArray *labels = [[NSMutableArray alloc] initWithCapacity:[labelsAxisX count]]; 
    int idx = 0; 
    for (NSString *product in labelsAxisX) 
    { 
     CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:product textStyle:x.labelTextStyle]; 
     label.tickLocation = CPTDecimalFromInt(idx); 
     label.offset = 5.0f; 
     [labels addObject:label]; 
     [label release]; 
     idx++; 
    } 

    x.axisLabels = [NSSet setWithArray:labels]; 
    [labels release]; 

回答

1

隨着CPTAxisLabelingPolicyNone標籤策略,您需要提供除蜱位置(主要和/或次要),以使標籤。如果您更願意使用固定時間間隔標記策略,則可以爲該軸返回文本標籤而不是數字的自定義數字格式器。

這裏是適合於在繪圖庫示例應用程序從標識政策演示一個例子:

NSMutableSet *tickLocations = [NSMutableSet set]; 
for (NSUInteger loc = 0; loc < labelsAxisX.count; loc++) { 
    [tickLocations addObject:[NSDecimalNumber numberWithUnsignedInteger:loc]]; 
} 
axis.majorTickLocations = tickLocations; 

次刻度位置相同的方式工作。

+0

如何?我已經修改我的職務與我用它來完成標籤的數組的代碼....但我不知道如何解決我的問題... – Davidin073

+0

感謝埃裏克!!!!!!!!!!! – Davidin073

+0

我希望做類似的事情:使用反映具有自定義標籤的可變數據的固定寬度策略。在我的情況下,幾個月。每個月可以有變量#數據;但我希望月份間隔是固定的(不像手動策略那樣可變)。如何用NSString(每個月)替換固定間隔的數字?
文獻:[鏈接] http://stackoverflow.com/posts/12631504/edit-submit/190af0df-e249-44bd-9490-5b46f826c905 –