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

Iphone 如何在图形中自定义CorePlot的绘图区域,iphone,objective-c,ios,graph,core-plot,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 bott

我正在使用核心图绘制图形。我试图在绘图区域上绘图,但它包含白色背景。但我想用我自己的背景画一幅图。这是我的密码

// 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轴上的每个记号绘制水平虚线。

设置y轴上的
majorGridLineStyle
和/或
minorGridLineStyle
,分别在主记号和次记号位置绘制水平线


使用线条样式的
dashPattern
patternPhase
属性制作虚线。有关这些属性如何工作的详细信息,请参见苹果的。

这是我在上面使用的代码

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

您的问题是关于绘图区域填充(您应该使用的)还是关于网格线?嘿!!Eric我想为y轴上的每个记号画一条水平虚线。嘿Eric这对我来说没用你能给我一些代码来完整地解释一下吗,因为我无法在何处使用此代码。嘿,Eric,我正在尝试使用patternPhase和dashPattern绘制虚线,但它显示了一个错误:无法设置对象-找不到只读属性或设置程序…嘿,Eric,我找到的答案是..CPTMutableLineStyle*dottedStyle=[CPTMutableLineStyle];dottedStyle.dashPattern=[NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:1],[NSDecimalNumber numberWithInt:2],nil];dottedStyle.patternPhase=0.0f;