2012-01-06 98 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]];