13

I am using iOS Charts with Swift 3.

I have a 100 x 100 PieChartView that renders the pie chart, but it's not filling the view (an NSView, to be precise). The gray box is the view and there's a large gap between the pie and the edge.

enter image description here

I have confirmed that the view is 100 x 100:

print(graph.frame) //<-- (25.0, 65.0, 100.0, 100.0)

So I assume there is something I need to configure in the pie chart to allow it to be the full size in the view. Here's what I've tried so far to no avail:

graph.holeRadiusPercent = 0.7
graph.transparentCircleRadiusPercent = 0  
graph.legend.enabled = false
graph.chartDescription?.enabled = false
graph.minOffset = 0

Any ideas?

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
  • You might want to look at the `extraTopOffset`, `extraRightOffset`, `extraBottomOffset` and `extraLeftOffset` properties (inherited from `ChartViewBase`) to make sure that these are `0.0` (they should be, by default, if I'm correct, but worth a look). – dfrib Feb 05 '17 at 10:07
  • I just tried those 4 properties as well and still no luck. Thanks, though! – Clifton Labrum Feb 06 '17 at 16:47
  • how did you have the gray circle as a based background circle in your pie chart ? for achieving this i had to add +1 data set , the extra for drawing a light gray slice to the end of the chart. but this one is not a good solution, do you have another solution for this ? – Maryam Fekri Jun 07 '17 at 10:39
  • @MaryamFekri I have two `PieChartDataSet` values, one for the color and the other for the gray part. So it's not actually a background, it's just the other, unused segment of the pie. – Clifton Labrum Jun 07 '17 at 20:43
  • yeah exactly what I have done to my chart, thanks – Maryam Fekri Jun 08 '17 at 10:15

1 Answers1

44

Found it! It turns out my graph was rendering the values in the pre-selection state. If I clicked on a pie segment, it would grow larger.

So by setting this property, the graph fills the available space:

ds.selectionShift = 0 //'ds' is my PieChartDataSet

I hope that helps someone else.

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
  • Yeap, it helped. Thanks a lot! – Artem Zaytsev Apr 15 '17 at 07:51
  • 1
    oh my god, this helped a lot! I played around with insets a little but didn't work.. the lib should really be better documented, as you can do almost everything with it but it is sometimes really hard to find the things you need.. – Heckscheibe Nov 02 '17 at 13:32
  • Thank you taking the time to answer your own question. I was going insane, and this was a tremendous help. – Tom Knapen Sep 09 '20 at 13:57