Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core plot axis labels not visible outside plot area

Tags:

ios

core-plot

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

like image 741
Perishable Dave Avatar asked Nov 22 '11 00:11

Perishable Dave


2 Answers

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.

like image 169
Eric Skroch Avatar answered Nov 08 '22 17:11

Eric Skroch


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;
like image 44
Miles Egan Avatar answered Nov 08 '22 18:11

Miles Egan