我正在使用核心图绘制图表。我试图在绘图区域绘制我的图表,但它包含白色背景。但我想用我自己的背景绘制图表。这是我的代码。
// 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
属性来制作虚线。参见 Apple 的 Quartz 2D docs有关这些属性如何工作的详细信息。
关于iphone - 如何在Graph中自定义CorePlot的绘图区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8767580/