我正在尝试将 core plot 与 swift 一起使用,除了一个错误外,我感觉非常接近。到目前为止我的代码是:
class ViewController: UIViewController, CPTPlotDataSource {
@IBOutlet weak var graphView: CPTGraphHostingView!
override func viewDidLoad() {
super.viewDidLoad()
// create graph
var graph = CPTXYGraph(frame: CGRectZero)
graph.title = "Hello Graph"
graph.paddingLeft = 0
graph.paddingTop = 0
graph.paddingRight = 0
graph.paddingBottom = 0
// hide the axes
var axes = graph.axisSet as CPTXYAxisSet
var lineStyle = CPTMutableLineStyle()
lineStyle.lineWidth = 0
axes.xAxis.axisLineStyle = lineStyle
axes.yAxis.axisLineStyle = lineStyle
// add a pie plot
var pie = CPTPieChart()
pie.dataSource = self
pie.pieRadius = (self.view.frame.size.width * 0.9)/2
graph.addPlot(pie)
self.graphView.hostedGraph = graph
}
func numberOfRecordsForPlot(plot: CPTPlot!) -> UInt {
return 4
}
func numberForPlot(plot: CPTPlot!, field fieldEnum: UInt, recordIndex idx: UInt) -> NSNumber! {
return idx+1
}
}
我收到的错误来自以下行:var pie = CPTPieChart() 我的错误是:
Core Plot with swift getting error : "Missing Argument for Parameter ‘frame’ in call"
我正在学习一个教程,swift 可能已经改变了,但是我是这门语言的新手,似乎无法解决这个问题。提前致谢。
请您参考如下方法:
我在开发另一个应用程序时遇到了类似的问题。根据我的经验,CGRectZero 会导致 Swift 出现问题。尝试使用实际的 CGRect 或调用
var pie = CPTPieChart(frame: CGRectMake(x,y,width,height))
