找不到MPAndroidChart错误类ValueFormatter

时间:2018-12-03 08:29:58

标签: java android android-studio

在我们的项目中将MPAndroidChart库here从'com.github.PhilJay:MPAndroidChart:v2.25更新到'com.github.PhilJay:MPAndroidChart:v3.0.2后,发生错误,指出该类找不到ValueFormatter。在进一步研究中,似乎有人在Maven存储库伪像索引上犯了一个错误,因为似乎v2.2.5是最新版本,而v3.0.2不是最新更新的版本here

1 个答案:

答案 0 :(得分:3)

I'm currently using this version on a working project

implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

And for formatting X and Y I'm using the followings imports

import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;

implementation look like this

public class MyValueFormatter implements IValueFormatter {

    private DecimalFormat mFormat;

    public MyValueFormatter() {
        mFormat = new DecimalFormat("###,###,##0"); // use one decimal
    }

    @Override
    public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
        // write your logic here
        return mFormat.format(value) + ""; // e.g. append a dollar-sign
    }
}