核心图:增加x轴上的刻度线之间的空间?

时间:2014-02-09 00:25:09

标签: ios core-plot

我有这个代码用于在x轴上制作刻度线和标签:

    CPTAxis *x = axisSet.xAxis;
    x.title = @"Hour of Day";
    x.titleTextStyle = axisTitleStyle;
    x.titleOffset = 15.0f;
    x.axisLineStyle = axisLineStyle;
    x.labelingPolicy = CPTAxisLabelingPolicyNone;
    x.labelTextStyle = axisTextStyle;
    x.majorTickLineStyle = axisLineStyle;
    x.majorTickLength = 4.0f;
    x.tickDirection = CPTSignNegative;
    CGFloat dateCount = [timestamps count];
    NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
    NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
    NSInteger i = 0;
    for (NSString *date in timestampStrings) {
        CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:date 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;

我想知道我是否可以扩大每个嘀嗒声之间的距离,因为现在它看起来就像一个混乱的混乱,与点不对齐。有没有办法在每个刻度之间留出更多空间,比如10个像素?谢谢!

2 个答案:

答案 0 :(得分:0)

我检查了它,它都在CGFloat location = i++;中撒谎。我将其更改为我想要的(5,像素一样),如下所示:

CGFloat location = i+=5;

并且有效。

答案 1 :(得分:0)

假设您使用CPTXYGraph及其CPTXYPlotSpace。使用plotSpace.globalXRangeplotSpace.xRange属性,您可以调整X轴的适当比例 globalXRange定义整个绘图区域,而xRange定义其可见空间。如果您不使用滚动,则xRange必须等于globalXRange