aks.knit1108
aks.knit1108

Reputation: 1305

How To Customize Plot Area of CorePlot in Graph

I am plotting graph using core plot. I am trying to plot my graph on plot area, but it contains white background. But I want to plot graph with my own background. This is my code.

// setting frame of graph
CGRect frame = [self.hostingView bounds]; 
self.graph = [[[CPTXYGraph alloc] initWithFrame:frame] autorelease];

// Add some padding to the graph, with more at the bottom for axis labels. 
self.graph.plotAreaFrame.paddingTop = 10.0f;  
self.graph.plotAreaFrame.paddingRight = 10.0f;  
self.graph.plotAreaFrame.paddingBottom = 25.0f;  
self.graph.plotAreaFrame.paddingLeft = 30.0f;

// set background color of plot area by fill property and CPTColor
self.graph.plotAreaFrame.plotArea.fill=[(CPTFill *)[CPTFill alloc] initWithColor: [CPTColor colorWithComponentRed:0.8 green:0.8 blue:0.8 alpha:1.0]]; 

// add graph to hosting view by hostedGraph property of hostingView    
self.hostingView.hostedGraph = self.graph;  

In above code I tried to change color but I want to draw horizontal dotted lines for each ticks on y axis.

Upvotes: 3

Views: 4744

Answers (2)

aks.knit1108
aks.knit1108

Reputation: 1305

This is my code which i have used for above....

    // create an object of CPTMutableLineStyle and set property of it.

    CPTMutableLineStyle *dottedStyle=[CPTMutableLineStyle lineStyle];
    dottedStyle.dashPattern=[NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1,[NSDecimalNumber numberWithInt:2],nil];
    dottedStyle.patternPhase=0.0f;

    // set the majorGridLinestyleProperty by this line as.

    axisSet.yAxis.majorGridLineStyle=dottedStyle;

Upvotes: 4

Eric Skroch
Eric Skroch

Reputation: 27381

Set the majorGridLineStyle and/or minorGridLineStyle on the y-axis to draw horizontal lines at the major and minor tick locations, respectively.

Use the dashPattern and patternPhase properties of the line style to make a dotted line. See Apple's Quartz 2D docs for details on how those properties work.

Upvotes: 4

Related Questions