如何在图形中自定义CorePlot的绘图区域

时间:2012-01-07 05:16:20

标签: iphone objective-c ios graph core-plot

我正在使用核心情节绘制图表。我试图在绘图区域绘制我的图形,但它包含白色背景。但我想用我自己的背景绘制图形。这是我的代码。

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

在上面的代码中,我尝试更改颜色,但我想为y轴上的每个刻度绘制水平虚线。

2 个答案:

答案 0 :(得分:5)

这是我上面用过的代码....

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

答案 1 :(得分:4)

在y轴上设置majorGridLineStyle和/或minorGridLineStyle,分别在主要和次要刻度位置绘制水平线。

使用线条样式的dashPatternpatternPhase属性制作虚线。有关这些属性如何工作的详细信息,请参阅Apple的Quartz 2D docs