0

我正在向我的应用程序添加散点图,并且我想在 X 轴标签上显示包含在数组 cogsetUsed (即自行车齿轮组)中的项目。项目的数量可以从 8 到 11。

我得到的是以下内容:

屏幕截图

这是一段代码:

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;

谢谢你的帮助!

4

1 回答 1

0

Core Plot 不能防止标签之间的冲突。不要求标记每个刻度线。由于您无论如何都要制作自定义轴标签,因此不要标记每个刻度位置。看起来您可以每隔三到四次标记一次以获得良好的外观。

于 2012-12-05T01:07:16.030 回答