Core plot axis labels not visible outside plot area
Asked Answered
B

2

8

I'm having some trouble with the axis labels. It seems my custom labels aren't visible outside of the plot area. Looking at the Design Overview for core plot, the axis labels should be outside of the plot area. Any ideas on how I can make them visible outside the plot area?

The code/image below shows how the labels only show within the plot area. If I change the label offset to a positive number, the labels do not show at all. I'm using Core Plot 0.9 with iOS 5.

Thanks in advance!

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];

Graph

Bloodsucker answered 22/11, 2011 at 0:31 Comment(0)
R
22

Set some padding on the plot area frame in addition to or instead of the graph itself.

graph.plotAreaFrame.paddingTop    = 20.0;
graph.plotAreaFrame.paddingBottom = 50.0;
graph.plotAreaFrame.paddingLeft   = 50.0;
graph.plotAreaFrame.paddingRight  = 50.0;

This code is from the axis demo in the Plot Gallery example app.

Rollo answered 22/11, 2011 at 2:33 Comment(2)
Thanks! Didn't see that option.Bloodsucker
coreplot is such a straight forward thing to use /sarcVyatka
L
7

I was having exactly the same problem and tried every solution I could find online for this with no success.

Finally I got it to work by turning off the border masking, like this:

graph.plotAreaFrame.masksToBorder = NO;
Letty answered 13/12, 2012 at 9:48 Comment(1)
This causes the labels to rendered outside of the bounds of the chart view. It might be a workable solution if you have left space around the view component, but it's worth being aware of.Medrek

© 2022 - 2024 — McMap. All rights reserved.