如何格式化MPAndroidChart中的值? [英] How to format values inside MPAndroidChart?
问题描述
2关于 MPAndroidChart库的问题. 我所有的yvalue都是整数,但显示为小数. 如何使它们显示为整数(无数字)? 如何防止ylabel也显示为小数? 我知道yvalue有一个setFormatter,只是不知道如何使用...
2 Questions about the MPAndroidChart library. All my yvalues are integers, but displayed as Decimals. How can I get them displayed as integers (without the digits)? How can I prevent that the ylabels are also shows as decimals? I know there is a setFormatter for the yvalues, just don't understand how to use...
推荐答案
看看IValueFormatter
界面.使用该界面,您可以根据自己的逻辑完全自定义图表上显示的内容.
Have a look at the IValueFormatter
interface provided by the library. With that interface, you can completely customize what gets displayed on the chart based on your own logic.
用法:
chart.setValueFormatter(new YourValueFormatter());
YLabels yl = chart.getYLabels();
yl.setFormatter(new YourValueFormatter());
更新(对于此[library] [2]的版本 2.0.0 + ):
UPDATE (for versions 2.0.0+ of this [library][2]):
现在,可以分别为每个DataSet
设置ValueFormatter
,或者可以为包含所有DataSets
的整个数据对象设置相同的ValueFormatter
.此外,YLabels
类现在称为YAxis
.
Now, a ValueFormatter
can be set for each DataSet
separately, or the same ValueFormatter
can be set for the whole data object containig all DataSets
. Furthermore, the YLabels
class is now called YAxis
.
示例:
// set for whole data object (individual DataSets also possible)
LineData data = new LineData(...);
data.setValueFormatter(new YourValueFormatter());
// YLabels are now called YAxis
YAxis yAxis = mChart.getAxisLeft(); // get the left or right axis
yAxis.setValueFormatter(new YourAxisValueFormatter());
更新(对于此[library] [2]的版本 3.0.0 + ):
UPDATE (for versions 3.0.0+ of this [library][2]):
用于格式化的接口已被重命名并扩展了其功能.现在,IAxisValueFormatter
可以用于格式化XAxis
和YAxis
的值. IValueFormatter
界面用于自定义图表值.
The interfaces for formatting have been renamed and extended in their functionality. Now, the IAxisValueFormatter
can be used to format values of both XAxis
and YAxis
. The IValueFormatter
interface is used to customize chart values.
链接到 ValueFormatter文档.
这篇关于如何格式化MPAndroidChart中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!