0

I have the following code:

xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
    public String getFormattedValue(float value, AxisBase axis) {
        int intValue = (int) value;
        int xVal = intValue / 120 / 12;

        if (xVal > prevXVal) {
            prevXVal = xVal;
            return ConvertUnits.toString(xVal);
        } else {
            return "";
        }
    }
});

For some unknown reason, no values are being displayed on the XAxis. I initialize prevXVal to 0, and if I remove the if statement I can see that the values on the X axis are correct. I basically want to remove repeated values from the X axis and only display the values when xVal changes. I'm not sure why this code wouldn't work, since I don't see how the if statement would always be false considering when I remove it I see the values changing.

Does anyone know what I am doing wrong?

Pink Jazz
  • 784
  • 4
  • 13
  • 34

1 Answers1

0

Okay, I figured it out. This seemed to do the trick:

xAxis.setValueFormatter(new IAxisValueFormatter() {
    @Override
    public String getFormattedValue(float value, AxisBase axis) {
        int intValue = (int) value;
        String xVal = ConvertUnits.toString(intValue / 120 / 12);

        if (!xVal.equals(prevXVal)) {
            prevXVal = xVal;
            if (xVal.equals("0")) {
                return "";
            } else {
                return xVal;
            }
        } else {
            return "";
        }
    }
});
Pink Jazz
  • 784
  • 4
  • 13
  • 34