Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

android - How to format values inside MPAndroidChart?

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Usage:

chart.setValueFormatter(new YourValueFormatter());
YLabels yl = chart.getYLabels();
yl.setFormatter(new YourValueFormatter());

UPDATE (for versions 2.0.0+ of this [library][2]):

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.

Example:

// 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());

UPDATE (for versions 3.0.0+ of this [library][2]):

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.

Link to the ValueFormatter documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...