2012-12-03 112 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不能防止标签之间的冲突。没有要求每个刻度标记都被标记。由于您正在制作自定义轴标签,因此不要标记每个打勾位置。看起来你可以标记每三分之一或四分之一刻度以获得一个好的外观。