leonidster
leonidster

Reputation: 71

iOS-Charts draw slice text outside the slices in pie chart

I want to draw the slice text outside the slices in pie chart, like in this image:

slice text outside slices

How can I achieve this?

Thanks :)

Upvotes: 3

Views: 2760

Answers (5)

Anuran Barman
Anuran Barman

Reputation: 1676

To do this you can try the following. If using PieChart it will draw the value outside of the slice with some line pointing to the right slice.

dataSet.yValuePosition = .outsideSlice

Above will give you the following result

PieChart Demo

Upvotes: 0

Hasya
Hasya

Reputation: 9898

When you are working with iOS chart , feature which you are expecting is not yet available.

Please refer.

Either you move with other library or still you could make max as per attached image.

enter image description here

You can download this code.

Upvotes: 0

Andres Gomez
Andres Gomez

Reputation: 458

you can try with this lines

charDataSet.valueFont = .systemFont(ofSize: 18)
charDataSet.valueLinePart1OffsetPercentage = 0.8
charDataSet.valueLinePart1Length = 0.05
charDataSet.valueLinePart2Length = 0.05
charDataSet.valueLineWidth = 0
charDataSet.yValuePosition = .outsideSlice

chart.transparentCircleRadiusPercent = 0
chart.holeColor = nil
chart.holeRadiusPercent = 0.8
chart.legend.enabled = false
chart.animate(xAxisDuration: 1)
chart.drawSlicesUnderHoleEnabled = false

regards

Upvotes: 1

Try this

pieChartDataSet.xValuePosition = .OutsideSlice

Upvotes: 9

fordrof
fordrof

Reputation: 117

I haven't used pie charts myself yet in ios-charts, but just looking at this (unfortunately incomplete) documentation , I would suggest trying to alter some of the values in the PieChartDataSet.

In Particular, xValuePosition, yValuePosition or ValuePosition.

In the bar chart class it is done like so barChartView.xAxis.labelPosition = .Bottom, hence my thinking it may be one of the above values. So have a play around and hopefully that helps you out! :)

Documentation: Charts Docs - PieChartDataSet

Upvotes: 1

Related Questions