MPAndroidChart,如何删除小数百分比而不显示低于10的百分比? [英] MPAndroidChart, how to remove decimal percentages and not show percentages below 10?

查看:485
本文介绍了MPAndroidChart,如何删除小数百分比而不显示低于10的百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MPAndroidChart ,我有两个问题:

I am using MPAndroidChart and I have two questions:

  • MPAndroid饼图删除十进制百分比
  • 在饼图上不显示小于10%的值,而是显示切片;百分比小于10%的文本不应显示.

推荐答案

更新版本3.0.0 +

格式化值是通过扩展ValueFormatter类并覆盖格式化所需的方法来完成的.也可以在此处插入自定义逻辑(例如,仅显示值大于10的标签).

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.

这篇关于MPAndroidChart,如何删除小数百分比而不显示低于10的百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆