How do remove the border around a core-plot graph
Asked Answered
P

7

24

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!

Perth answered 3/2, 2010 at 18:17 Comment(2)
I am sorry if this is an obvious question but what is a core plot graph?Endor
Core Plot is a library for graphing on the mac and on the iphone: code.google.com/p/core-plotPerth
L
78

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.

Longicorn answered 4/2, 2010 at 5:16 Comment(3)
If you are using a built-in theme, make sure you set the borderLineStyle AFTER the applyTheme call, or it'll get overwritten.Strafford
This comment is golden! Thanks! I had some testcode and just switched themes via a button. So everything got overwritten!Movement
Just to add to Brad's answer. Please add the line mentioned in the answer after applying the theme. If you add it before that then it won't work.Snub
M
8

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;
Movement answered 21/2, 2013 at 2:53 Comment(0)
P
4

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?

Perth answered 3/2, 2010 at 21:52 Comment(0)
I
1

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

Interact answered 4/2, 2010 at 0:23 Comment(0)
H
1

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;
Hamlet answered 27/7, 2012 at 20:28 Comment(0)
P
1

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;
Paraphrastic answered 2/9, 2014 at 11:28 Comment(0)
I
1

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;
Immorality answered 12/5, 2015 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.