核心图:X轴标签卷曲

时间:2012-12-03 20:41:07

标签: objective-c ios core-plot xcode4.5

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

我得到的是以下内容:

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;

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

Core Plot不会阻止标签之间的冲突。不要求每个刻度标记都被标记。由于您无论如何都在制作自定义轴标签,因此请勿标记每个刻度位置。看起来您可以标记每三分之一或四分之一以获得良好的外观。