MPAndroidChart:如何自定义条值标签 [英] MPAndroidChart: How to customise bar value labels
问题描述
我在Android应用中使用MPAndroidChart.我使用由BarEntry
组成的BarChart
.我还使y值显示在栏的顶部.
I am using MPAndroidChart in my Android app. I use a BarChart
composed of BarEntry
. I also enabled the y-values to be displayed on top of the bar.
我的问题是我希望条形图顶部的值是像5
这样的整数.但是当前值显示为5.00
.
My issue is that I want the values on top of the bars to be whole numbers like 5
. But currently the values display as 5.00
.
那么如何使5.00
显示为5
?
推荐答案
使用IValueFormatter
界面格式化值.这是一个简单的格式化程序,可将所有值转换为整数:
Values are formatted using the IValueFormatter
interface. Here's a simple formatter that converts all values to integers:
public class IntValueFormatter implements IValueFormatter {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return String.valueOf((int) value);
}
}
然后可以将此格式化程序用于BarData
和单个BarDataSet
对象,如下所示:
You can then use this formatter for both BarData
and individual BarDataSet
objects like this:
barData/barDataSet.setValueFormatter(new IntValueFormatter());
有关IValueFormatter
的更多信息,请检查以下链接:
For more information on IValueFormatter
, check the following links:
-
Github上的
-
IValueFormatter
Wiki
IValueFormatter
Wiki on GithubIValueFormatter
Documentation on JitPack (v3.0.0-beta1)
这篇关于MPAndroidChart:如何自定义条值标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!