Reputation: 515
Using core plot CPTXYGraph, I want to add a background behind the axes but on top of plot line. As far as my research, the only way to do this is to add a custom CPTLayer, and try to position it correctly. My problem is the CPTLayer always grows to full size of the graph despite the frame I set. How can I solve this? Thanks.
CPTLayer *layer = [CPTLayer layer];
layer.frame = CGRectMake(0, 0, 200, 200);
layer.backgroundColor = [[UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:0.6] CGColor];
[self.graph addSublayer:layer];
Upvotes: 1
Views: 1149
Reputation: 6158
Look in to this http://www.raywenderlich.com/13269/how-to-draw-graphs-with-core-plot-part-1 and http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2.You can get clear idea about core plot.
Upvotes: 1
Reputation: 27381
You can add your layer to the graph as an "annotation". Create a layer annotation, set your CPTLayer
as the content layer, and add the annotation to the graph.
Upvotes: 0
Reputation: 2357
Make your view a subclass of CPTGraphHostingView
Then , In Implementation
CPTXYGraph *graph;
hostingView = (CPTGraphHostingView *)hostingView;
hostingView.hostedGraph = graph;
CPTLayer *subLayer = [[CPTLayer alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
subLayer.backgroundColor = [UIColor redColor].CGColor;
[self.hostingView.layer addSublayer:subLayer];
Upvotes: 3