PhilJay / MPAndroidChart

A powerful 🚀 Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, panning and animations.
Other
37.64k stars 9.02k forks source link

Hide small values in a pie chart MPAndroidChart #4710

Open tommasobo opened 5 years ago

tommasobo commented 5 years ago

How can I hide small values in a PieChart if I am printing them outside the graph? I can get the label to be empty with a ValueFormatter but I can't understand how I would delete the line going outside the graph.

This is my current situation (without the Value Formatter to hide small values): https://i.imgur.com/CbGjGZZ.png

Kpieta commented 4 years ago

Cannot find simple and short solution for this bug so I fix it simple overriding ValueFormatter.


 class CustomPieNumberFormatter(var pieChart: PieChart?) : PercentFormatter(pieChart) {

        val OVERLAP_LIMIT = 3.5

        override fun getPieLabel(value: Float, pieEntry: PieEntry?): String {
            return if (pieChart != null && pieChart!!.isUsePercentValuesEnabled) {
                if (value < OVERLAP_LIMIT)
                    ""
                else
                    getFormattedValue(value)
            } else {
                // raw value, skip percent sign
                mFormat.format(value.toDouble())
            }
        }
    }