2016-06-17 83 views
1

我試圖使用核心情節設計一個三維餅圖使用核心情節。 因此,我有以下代碼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 我更新了我的數據源和委託方法。 是沒有過於我得到這個輸出 - 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)") 
} 
+0

我在一個核心情節的示例應用程序嘗試這種覆蓋的設置,它看起來OK。餅圖是否正確顯示沒有過度?什麼樣的數據源和委託方法被實現,他們返回什麼?餡餅中有多少片?它有切片周圍的邊界線嗎?如果是這樣,用什麼線條樣式來繪製邊框線? –

+0

嗨@EricSkroch我更新了數據源和委託方法。你可以通過提供一些代碼示例來幫助我。謝謝 – kalpa

+0

沒有過度的餅圖嗎? 'pieItem'(片數)的值是多少? –

回答

2

我自己固定它。我犯了一個愚蠢的錯誤。 取而代之的是

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)