Skip to content Skip to sidebar Skip to footer

How Can I Alter The Spacing For The Y-axis Labels In Mpandroidchart?

How can I make my YAxis labels elevated with a gap i.e., start from a given value like the below picture? If I try using offset it makes my YAxis label values plot incorrectly agai

Solution 1:

This was achieved through implementing IAxisValueFormatter because I wanted to keep all values and just modify the labels:

publicclassMyValueFormatterimplementsIAxisValueFormatter {

    privatefinalfloat cutoff;
    privatefinal DecimalFormat format;

    publicMyValueFormatter(float cutoff) {
        this.cutoff = cutoff;
        this.format = newDecimalFormat("###,###,###,##0.00");
    }

    @Overridepublic String getFormattedValue(float value, AxisBase axis) {
        if (value < cutoff) {
            return"";
        }

        return"$" + format.format(value);
    }
}

And then I consume it using:

leftAxis.setValueFormatter(newMyValueFormatter(yMin));

where yMin was defined earlier:

privatefloat yMin = 0; 

and then assigned the chart's minimum yValue was passed in.

a chart with the YAxis labels starting from the minimum yValue as per OP's requirement

Post a Comment for "How Can I Alter The Spacing For The Y-axis Labels In Mpandroidchart?"