简体   繁体   English

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

[英]Core Plot: Increase space between ticks on the x-axis?

I have this code for making ticks and labels on the x-axis: 我有这个代码用于在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;

I was wondering if I could expand the distance between each tick, because right now it just looks like a squished together mess that does not align with the points. 我想知道我是否可以扩大每个刻度线之间的距离,因为现在它看起来像一个混乱的混乱,与点不对齐。 Is there any way to make more space in between each tick, say 10 pixels? 有没有办法在每个刻度之间留出更多空间,比如10个像素? Thanks! 谢谢!

I checked into it, and it all lied in the CGFloat location = i++; 我检查了它,它都在CGFloat location = i++;撒谎CGFloat location = i++; . I changed that to what I wanted (5, as in pixels) like this: 我将其更改为我想要的(5,像素一样),如下所示:

CGFloat location = i+=5;

and that worked. 那很有效。

Assuming you use CPTXYGraph and its CPTXYPlotSpace . 假设您使用CPTXYGraph及其CPTXYPlotSpace Using the plotSpace.globalXRange and plotSpace.xRange properties you can adjust proper scale for the X-axis. 使用plotSpace.globalXRangeplotSpace.xRange属性,您可以调整X轴的适当比例。
The globalXRange defines the whole plot area, while the xRange defines its visible space. globalXRange定义整个绘图区域,而xRange定义其可见空间。 If you do not use scrolling, then xRange must be equal to globalXRange . 如果不使用滚动,则xRange必须等于globalXRange

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM