Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart setValueFormatter requires ValueFormater not IAxisValueFormatter

so basicly recently I started programming mobile apps and found a problem in my application. I want XAxis values of my line chart in 19:30 format, not 3244 minutes passed format, so I googled AxisFormatters. The problem is, in all of the tutorials they make class like this:

private class MyAxisFormatter implements IAxisValueFormatter {

    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        return value as an hour;
    }
}

and then put it in function:

    XAxis valAxis = mChart.getXAxis();
    valAxis.setValueFormatter(new MyAxisFormatter());

But whenever I impement it into this I got red underline saying: Required type: ValueFormatter Provided: MyAxisFormatter

I tried to cast it somehow to ValueFormatter but that didnt work, solution that program prompts me is to make MyAxisFormater extend ValueFormatter although i dont get any errors then that doesnt change any value on my XAxis

like image 1000
Maciej Scheffer Avatar asked Oct 19 '25 04:10

Maciej Scheffer


1 Answers

Ok I got it, instead of using

private class MyAxisFormatter implements IAxisValueFormatter {
 @Override
 public String getFormattedValue(float value, AxisBase axis) {
     return value as an hour;
 }
}

I used

private class MyAxisFormatter extends ValueFormatter {
    @Override
    public String getFormattedValue(float value) {
        return "someValue";
    }
}

And everything works fine

like image 105
Maciej Scheffer Avatar answered Oct 21 '25 20:10

Maciej Scheffer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!