12
votes

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?

1
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
I just tried those 4 properties as well and still no luck. Thanks, though! - Clifton Labrum
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
@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
yeah exactly what I have done to my chart, thanks - Maryam Fekri

1 Answers

35
votes

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.