2012-12-03 111 views
0

我加入散點圖到我的應用程序和我要顯示在X軸上標籤包含在數組中,cogsetUsed(即,一種自行車後變速盤)的項目。項目數可以從8到11核心劇情:X軸標籤蜷縮

我得到的是以下幾點:

screen capture

這是一段代碼:

CPTGraph *graph = self.hostView.hostedGraph; 
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 

CPTXYAxis *x = axisSet.xAxis; 

x.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInteger(0) length:CPTDecimalFromInteger(12)]; 
x.labelingPolicy = CPTAxisLabelingPolicyNone; 
x.labelTextStyle = axisTextStyle; 
x.majorTickLineStyle = axisLineStyle; 
x.majorTickLength =4.0f; 
x.tickDirection =CPTSignNegative; 
CGFloat recordCount = [cogsetUsed count]; 
NSMutableSet *xLabels =[NSMutableSet setWithCapacity:recordCount]; 
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:recordCount]; 
NSInteger i =0; 
for (NSString *sprocket in cogsetUsed) { 
    CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:sprocket textStyle:x.labelTextStyle]; 
    CGFloat location = i++; 
    label.tickLocation = CPTDecimalFromCGFloat(location); 
    label.offset =x.majorTickLength; 
    if (label) { 
     [xLabels addObject:label]; 
     [xLocations addObject:[NSNumber numberWithFloat:location]]; 
    } 
} 
x.axisLabels = xLabels; 
x.majorTickLocations = xLocations; 

感謝您的幫助!

回答

0

Core Plot不能防止標籤之間的衝突。沒有要求每個刻度標記都被標記。由於您正在製作自定義軸標籤,因此不要標記每個打勾位置。看起來你可以標記每三分之一或四分之一刻度以獲得一個好的外觀。