How do remove the border around a core-plot graph

余生颓废 提交于 2019-12-02 17:34:10
Brad Larson

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.

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;

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?

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

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;

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

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;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!