【发布时间】:2010-06-17 09:15:46
【问题描述】:
我已经完成了几天工作的核心情节图。 我仍然无法做的事情(我找不到这方面的文档),就是将 x 轴标签更改为我需要的。 今天,我有一个 x 轴,每 5 个值显示一个整数标签:“5 10 15 ...”,我需要对应过去 24 小时的标签。例如,如果现在是 15:00,我需要如下标签:“15 16 17 ... 23 0 1 2 .. 15”我正在考虑为此使用 NSArray 并将其传递给 plotSpace.xRange 但我没有知道这是否是这样做的好方法。 这是我的代码:
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-15)
length:CPDecimalFromFloat(xmax + 15)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-1000)
length:CPDecimalFromFloat(4300)];
// Setup axis
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPLineStyle *lineStyle = [CPLineStyle lineStyle];
lineStyle.lineColor = [CPColor whiteColor];
lineStyle.lineWidth = 1.0f;
CPTextStyle *cyanStyle = [CPTextStyle textStyle];
cyanStyle.color = [CPColor cyanColor];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:0];
axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue];
axisSet.xAxis.minorTicksPerInterval = 0;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLength = 5.0f;
axisSet.xAxis.labelOffset = 3.0f;
axisSet.xAxis.labelExclusionRanges = [NSArray arrayWithObjects:
[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-15)
length:CPDecimalFromFloat(15)],
nil];
axisSet.xAxis.visibleRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromInteger(0) length:CPDecimalFromInteger(xmax)];
axisSet.xAxis.labelFormatter = formatter;
axisSet.xAxis.title = @"Hour";
axisSet.xAxis.titleOffset = 25.0f;
axisSet.xAxis.titleLocation = CPDecimalFromFloat(25.0f);
axisSet.xAxis.titleTextStyle = cyanStyle;
非常欢迎任何帮助:) 非常感谢, 卢克
【问题讨论】: