gpt4 book ai didi

swift - 快速使用 Core Plot 的 3D 饼图

转载 作者:搜寻专家 更新时间:2023-11-01 07:22:45 24 4
gpt4 key购买 nike

我正在尝试使用核心图设计 3D 饼图。这样我就有了下面的代码

    @IBOutlet weak var pieChartDataLabel: UILabel!
@IBOutlet weak var graphView: CPTGraphHostingView!
var pieItem:Int = 0
var pieChartValueArrayToShow = [AnyObject]()
override func viewDidLoad() {
super.viewDidLoad()

let graph = CPTXYGraph(frame: CGRectZero)
graph.title = "PieChart"
graph.paddingLeft = 0
graph.paddingTop = 0
graph.paddingRight = 0
graph.paddingBottom = 0
graph.backgroundColor = UIColor.brownColor().CGColor

let overlayGradient = CPTGradient()
overlayGradient.gradientType = CPTGradientType.Radial
overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.0), atPosition: 0.9)
overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.4), atPosition: 1.0)

let pie = CPTPieChart()
//pie.borderLineStyle = linestyle
pie.dataSource = self
pie.delegate = self
pie.pieRadius = (self.view.frame.size.width * 0.7)/2
pie.overlayFill = CPTFill(gradient: overlayGradient)
graph.addPlot(pie)
self.graphView.hostedGraph = graph;
// Do any additional setup after loading the view.
}

但我得到的是白色饼图。这是我的输出图像。 https://drive.google.com/open?id=0B9YZfopxzOv5UG9hQmRjZGVQdzQ我更新了我的数据源和委托(delegate)方法。是的,不过分,我得到了这个输出 - https://drive.google.com/open?id=0B9YZfopxzOv5Uy14NXlQYkJZY1k

func numberOfRecordsForPlot(plot: CPTPlot) -> UInt {
return UInt(pieItem)
}

func numberForPlot(plot: CPTPlot, field fieldEnum: UInt, recordIndex idx: UInt) -> AnyObject? {
return pieChartValueArrayToShow[Int(idx)]
}

func pieChart(plot: CPTPieChart, sliceWasSelectedAtRecordIndex idx: UInt) {
print("dataLabel was selected At Record Index getting called")
self.pieChartDataLabel.text = "Your selected value is \(pieChartValueArrayToShow[Int(idx)])"
}

这是我的 Prepareforsegue 方法,我在其中分配 pieChartValueArrayToShowpieItem

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "ShowPieChart") {
let desinationviewController = segue.destinationViewController as! PieChartViewController

let count = pieChartValueArray.count as Int
print(count)
desinationviewController.pieItem = count//(sender?.integerValue)!//pieChartValueArray.count//
print("count is \(pieChartValueArray.count)")
desinationviewController.pieChartValueArrayToShow = pieChartValueArray
}
print("Prepare segue getting called\(sender)")
}

最佳答案

我自己修的。我犯了一个愚蠢的错误。而不是这个

overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.0), atPosition: 0.9)
overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.4), atPosition: 1.0)

我写了

overlayGradient = overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.0), atPosition: 0.8)
overlayGradient = overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.4), atPosition: 1.0)

关于swift - 快速使用 Core Plot 的 3D 饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37879621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com