我有这个代码用于在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个像素?谢谢!
答案 0 :(得分:0)
我检查了它,它都在CGFloat location = i++;
中撒谎。我将其更改为我想要的(5,像素一样),如下所示:
CGFloat location = i+=5;
并且有效。
答案 1 :(得分:0)
假设您使用CPTXYGraph
及其CPTXYPlotSpace
。使用plotSpace.globalXRange
和plotSpace.xRange
属性,您可以调整X轴的适当比例
globalXRange
定义整个绘图区域,而xRange
定义其可见空间。如果您不使用滚动,则xRange
必须等于globalXRange
。