问题
I have this code for making ticks and labels on the x-axis:
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? Thanks!
回答1:
I checked into it, and it all lied in the CGFloat location = i++;
. I changed that to what I wanted (5, as in pixels) like this:
CGFloat location = i+=5;
and that worked.
回答2:
Assuming you use CPTXYGraph
and its CPTXYPlotSpace
. Using the plotSpace.globalXRange
and plotSpace.xRange
properties you can adjust proper scale for the X-axis.
The globalXRange
defines the whole plot area, while the xRange
defines its visible space. If you do not use scrolling, then xRange
must be equal to globalXRange
.
来源:https://stackoverflow.com/questions/21653573/core-plot-increase-space-between-ticks-on-the-x-axis