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

问题描述:

我正在绘制使用核心绘图的绘图。我试图在绘图区域绘制我的图形,但它包含白色背景。但我想用我自己的背景来绘制图。这是我的代码。如何在图中自定义CorePlot的绘图区域

// 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轴上每个刻度的水平虚线。

+0

您对绘图区域的填充(你有什么应该工作)疑问或网格线? – 2012-01-07 20:38:34

+0

嘿!埃里克我想为y轴上的每个tickMark绘制水平虚线。 – 2012-01-08 13:37:54

这是我的代码,我已经使用了上面....

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

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

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

+0

嘿埃里克这对我没有用,你可以给我一些代码来完全解释它,因为我无法在这里使用这段代码。 – 2012-01-09 05:42:48

+0

嘿埃里克它完全工作。谢谢 !! – 2012-01-09 06:23:38

+0

嘿埃里克我试图绘制虚线与patternPhase和dashPattern,但它显示一个错误:对象无法设置 - 只读属性或没有找到setter ... – 2012-01-09 06:58:32