我在使用轴标签时遇到了一些麻烦。看来我的自定义标签在绘图区域外是不可见的。查看核心图的Design Overview,轴标签应位于绘图区域之外。关于如何让它们在情节区域外可见的任何想法?
下面的代码/图片显示了标签仅在绘图区域内显示的方式。如果我将标签偏移更改为正数,则标签根本不显示。我在iOS 5中使用Core Plot 0.9。
提前致谢!
CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
graph = [[theme newGraph] retain];;
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
hostingView.hostedGraph = graph;
graph.paddingLeft = 40.0;
graph.paddingTop = 40.0;
graph.paddingRight = 40.0;
graph.paddingBottom = 40.0;
graph.masksToBorder = NO;
// ... setup axis
axisSet.yAxis.majorIntervalLength = CPTDecimalFromInt(0);
axisSet.yAxis.minorTicksPerInterval = 0;
axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
// if this number is negative, the labels show,
// if it is positive, that is outside the plot area, the labels are hidden.
axisSet.yAxis.labelOffset = -20;
// ... setup labels
NSMutableArray *labels = [NSMutableArray array];
for (int i = 0; i < reportData.rowCount; ++i) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"Test Row %i", i] textStyle:labelStyle];
label.tickLocation = CPTDecimalFromInt(i);
label.offset = axisSet.yAxis.labelOffset;
label.alignment = CPTAlignmentLeft;
[labels addObject:label];
[label release];
}
axisSet.yAxis.axisLabels = [NSSet setWithArray:labels];
答案 0 :(得分:21)
除了图形本身之外或代替图形本身,在绘图区域框架上设置一些填充。
graph.plotAreaFrame.paddingTop = 20.0;
graph.plotAreaFrame.paddingBottom = 50.0;
graph.plotAreaFrame.paddingLeft = 50.0;
graph.plotAreaFrame.paddingRight = 50.0;
此代码来自Plot Gallery示例应用程序中的轴演示。
答案 1 :(得分:7)
我遇到了完全相同的问题并尝试了我可以在网上找到的所有解决方案,但没有成功。
最后,我通过关闭边框遮罩来实现它,就像这样:
graph.plotAreaFrame.masksToBorder = NO;