How do remove the border around a core-plot graph

后端 未结 7 1985
北荒
北荒 2021-01-31 18:42

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条回答
  • 2021-01-31 18:58

    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.

    0 讨论(0)
  • 2021-01-31 18:59

    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;
    
    0 讨论(0)
  • 2021-01-31 19:01

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

    0 讨论(0)
  • 2021-01-31 19:07

    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?

    0 讨论(0)
  • 2021-01-31 19:13

    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;
    
    0 讨论(0)
  • 2021-01-31 19:17

    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;
    
    0 讨论(0)
提交回复
热议问题