Reputation: 21
How to make pie chart code like this, I have used many libraries like MPAndroidChart for it but none of them prevents overlapping of labels
my current approach with MPAndroidChart is
val ds = PieDataSet(entries, "")
ds.colors = Utils.colors.map { it.toArgb() }
ds.yValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE
ds.xValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE
ds.sliceSpace = 1.5f
ds.valueTextColor = Black33.toArgb()
ds.valueTextSize = 12f
ds.isUsingSliceColorAsValueLineColor = true
ds.valueLinePart1Length = 1f
ds.valueLinePart2Length = 1f
ds.valueLinePart1OffsetPercentage = 100f
ds.valueTypeface = opensans
ds.valueFormatter = object : ValueFormatter() {
override fun getFormattedValue(value: Float): String {
return "%.1f%%".format(value)
}
}
chart.setEntryLabelTextSize(13f)
chart.setEntryLabelTypeface(nunito)
chart.minAngleForSlices = 25f
chart.isRotationEnabled = true
val d = PieData(ds)
chart.data = d
chart.invalidate()
I have tried minimizing it by using "minAngleForSlices" but that doesn't seem to be a good solution solution
Upvotes: 1
Views: 44