2012-01-07 53 views
4

我正在繪製使用核心繪圖的繪圖。我試圖在繪圖區域繪製我的圖形,但它包含白色背景。但我想用我自己的背景來繪製圖。這是我的代碼。如何在圖中自定義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

回答

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

在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