1

I am trying to design a 3D PieChart using core plot. So that I have the following code

    @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.
}

But I am getting a white color pie chart. here is the image of my output. https://drive.google.com/open?id=0B9YZfopxzOv5UG9hQmRjZGVQdzQ I updated my data source and delegate method. Yes without overly I am getting this output - 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)])"
}

This is my Prepareforsegue Method where I am assigning the pieChartValueArrayToShow and pieItem

    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)")
}
15
  • I tried this overlay setup in a Core Plot example app and it looked ok. Does the pie chart appear correctly without the overly? What datasource and delegate methods are implemented and what do they return? How many slices are in the pie? Does it have a border line around the slices? If so, what line style is used to draw the border line? Commented Jun 17, 2016 at 23:26
  • Hi @EricSkroch I updated the data source and delegate methods. Can you help me by giving some code sample. Thanks Commented Jun 18, 2016 at 4:40
  • Does the pie chart appear correctly without the overly? What is the value of pieItem (the slice count)? Commented Jun 18, 2016 at 11:57
  • Yes, PieItem is the slice count and without overly the pie chart appears correctly. Here is the Image ( drive.google.com/open?id=0B9YZfopxzOv5Uy14NXlQYkJZY1k) Commented Jun 20, 2016 at 3:16
  • Is this a screenshot and not a PDF? Partially transparent elements don't render properly in PDFs. Commented Jun 21, 2016 at 2:10

1 Answer 1

2

I fixed it by myself. I did a stupid mistake. Instead of this

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

I Wrote

overlayGradient = overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.0), atPosition: 0.8)
    overlayGradient = overlayGradient.addColorStop(CPTColor.blackColor().colorWithAlphaComponent(0.4), atPosition: 1.0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.