Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart, how to remove decimal percentages and not show percentages below 10?

I am using MPAndroidChart and I have two questions:

  • MPAndroid Pie Chart Remove decimal percentages
  • Not show values on the Pie Chart that have values less than 10%, but show the slice; just the text should not be shown for the percentages less than 10%.
like image 277
abhishek Avatar asked Oct 29 '15 20:10

abhishek


1 Answers

Update for version 3.0.0+

Formatting values is now done by extending the ValueFormatter class and overriding the required methods for formatting. This is also where custom logic (e.g. only show labels for values > 10) can be inserted.

class MyValueFormatter : ValueFormatter() {
    private val format = DecimalFormat("###,##0.0")

    // override this for e.g. LineChart or ScatterChart
    override fun getPointLabel(entry: Entry?): String {
        return format.format(entry?.y)
    }
}

More examples and a detailed explanation can be found in the new documentation.

like image 63
Philipp Jahoda Avatar answered Oct 16 '22 19:10

Philipp Jahoda