24
votes

I am trying to remove the border around a core plot graph on the iPhone - but seem to be struggling on what should be simple in my mind.

Pointers please!

7
I am sorry if this is an obvious question but what is a core plot graph? - Oscar Gomez
Core Plot is a library for graphing on the mac and on the iphone: code.google.com/p/core-plot - Grouchal
That looks really useful. Thank you. - Oscar Gomez

7 Answers

78
votes

You should be able to nil out the borderLineStyle on the graph's plotArea to remove the border:

graph.plotAreaFrame.borderLineStyle = nil;    // don't draw a border

You could also create your own theme, using the ones in the framework as examples, and simply not set the borderLineStyle in that.

8
votes

None of the answers worked for me. This did the job:

graph.paddingLeft = 0;
graph.paddingRight = 0;
graph.paddingTop = 0;
graph.paddingBottom = 0;
graph.plotAreaFrame.borderWidth = 0;
graph.plotAreaFrame.cornerRadius = 0;
4
votes

OK I found out how to do it - quite simple really!

CPLineStyle *borderLineStyle = [CPLineStyle lineStyle];
borderLineStyle.lineColor = [CPColor whiteColor];
borderLineStyle.lineWidth = 1.0;

graph.plotArea.borderLineStyle = borderLineStyle;

where graph is your graph object - the reason I had a border in the first place was because I used CPPlainWhiteTheme.

Hope this helps others - is there a better way?

1
votes

You can set any line style to nil. This will cause the line to not be drawn at all.

1
votes

In CorePlot 1.0, the structure of CPTGraph has changed slightly. The code for removing the border line of a graph, assuming that graph is of type GPTGraph or a subclass of CPTGraph, is

graph.plotAreaFrame.borderLineStyle = nil;
1
votes

The correct way with borderLineStyle = nil after applyTheme:

CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];

// Set padding for plot area
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
graph.plotAreaFrame.borderLineStyle = nil;
1
votes

If, like me, you are looking to not just remove the border line, but to make a plot that takes up the entire hosting view, the answer from Thomas Johannesmeyer got me on the right track.

Here's what I did:

CPTGraphHostingView* hostingView = [[CPTGraphHostingView alloc] initWithFrame: frame];
CGRect bounds = hostingView.bounds;

CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds];
hostingView.hostedGraph     = graph;

graph.paddingTop    = CPTFloat(0.0);
graph.paddingRight  = CPTFloat(0.0);
graph.paddingBottom = CPTFloat(0.0);
graph.paddingLeft   = CPTFloat(0.0);

graph.plotAreaFrame.paddingTop    = CPTFloat(0.0);
graph.plotAreaFrame.paddingRight  = CPTFloat(0.0);
graph.plotAreaFrame.paddingBottom = CPTFloat(0.0);
graph.plotAreaFrame.paddingLeft   = CPTFloat(0.0);
graph.plotAreaFrame.masksToBorder = NO;

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x          = axisSet.xAxis;
x.labelingPolicy      = CPTAxisLabelingPolicyNone;
x.title = nil;
CPTXYAxis *y          = axisSet.yAxis;
y.labelingPolicy      = CPTAxisLabelingPolicyNone;
y.title = nil;