iphone - 如何在Graph中自定义CorePlot的绘图区

标签 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 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 以分别在主要和次要刻度位置绘制水平线。

使用线条样式的 dashPatternpatternPhase 属性来制作虚线。参见 Apple 的 Quartz 2D docs有关这些属性如何工作的详细信息。

关于iphone - 如何在Graph中自定义CorePlot的绘图区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8767580/

相关文章:

jquery - 从 iPhone 主屏幕重新打开时,如何在 jQuery Mobile 应用程序上缓存和保留上次访问的页面?

iOS - 奇怪的越界异常

ios - 在 UIPageViewController 上将 TranslatesAutoresizingMaskIntoConstraints 设置为 No

iphone - 强制iphone应用程序以编程方式重新启动?

ios - VSTS 任务 Apple App Store 要求提供 2FA 代码,但已设置 FaSTLane Session 和 App-Specific

ios - Xcode 10 'frame' is only available on iOS 12.0 or newer 编译错误 iOS 12 beta

iphone - 如何使用 Core Graphics/Quartz 创建实心圆的一部分

iphone - 如何在下载之前获取文档大小

iphone - UISegmentedControl 部署在 iOS 5 和 iOS 5.1 上的不同行为

ios - IOS 中表格 View 单元格点击的背景颜色更改