2012-01-06 93 views
2

我正在繪製使用核心繪圖的繪圖圖。我試圖在繪圖區域繪製我的圖形,但它包含白色背景。但我想用我自己的背景來繪製圖。這是我的代碼。如何使用自定義視圖設置核心繪圖圖的繪圖區

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; 
self.graph.plotAreaFrame.plotArea.fill=[(CPTFill *)[CPTFill alloc] initWithColor: [CPTColor colorWithComponentRed:0.8 green:0.8 blue:0.8 alpha:1.0]]; 

// Tie the graph we've created with the hosting view. 
self.hostingView.hostedGraph = self.graph; 
} 

在上面的代碼中,我試圖改變顏色,但我想繪製水平虛線爲每個在Y軸上蜱。

回答

0

要繪製水平線,請將y軸的majorGridLineStyle和/或minorGridLineStyle設置爲分別從主刻度線和次刻度線繪製線。使用線型的dashPatternpatternPhase屬性來控制點圖案。有關如何使用這些線條樣式屬性的詳細信息,請參閱Apple的Quartz 2D docs

0

試試這個: -

//configure plot method 
    //0 - Create Theme 
    CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme]; 

    // 1 - Create the graph 
    CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.GraphView.frame]; 
    graph = (CPTXYGraph *)[theme newGraph]; 
    graph.fill = [CPTFill fillWithColor:[CPTColor clearColor]]; 
    graph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]]; 
相關問題