0
I have created one ValueFormatter class.
public class MyValueFormatter extends ValueFormatter
{

    private final DecimalFormat mFormat;
    private String suffix;

    public MyValueFormatter(String suffix) {
        mFormat = new DecimalFormat("###,###,###,##0.0");
        this.suffix = suffix;
    }

    @Override
    public String getFormattedValue(float value) {
         return "" + ((int) value);
    }

    @Override
    public String getAxisLabel(float value, AxisBase axis) {
        if (axis instanceof XAxis) {
            return mFormat.format(Math.round(value));
        } else if (value > 0) {
            return mFormat.format(Math.round(value)) + suffix;
        } else {
            return mFormat.format(Math.round(value));
        }
    }
}

Created one ArrayList.

    ArrayList<BarEntry> NoOfEmp = new ArrayList<BarEntry>();
    NoOfEmp.add(new BarEntry( 0f,jan));

finally call ValueFormatter:

        ValueFormatter custom = new MyValueFormatter("");

        YAxis leftAxis = chart.getAxisLeft();
//        leftAxis.setTypeface(tfLight);
//        leftAxis.setLabelCount(8, false);
        leftAxis.setValueFormatter(custom);
        leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
        leftAxis.setSpaceTop(15f);
        leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setDrawGridLines(false);
//        rightAxis.setTypeface(tfLight);
//        rightAxis.setLabelCount(8, false);
        rightAxis.setValueFormatter(custom);
        rightAxis.setSpaceTop(15f);
        rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

        chart.setData(data);

I have used getFormatted method for setValueFormatter(custom). but its not working

output :

0.0
0.0
1.0
1.0
2.0
2.0

need only integer.

I am learning to implement chart in android. I need to convert float value to integer.

Christoph John
  • 3,003
  • 2
  • 13
  • 23
Darshan Thakar
  • 11
  • 1
  • 1
  • 4

0 Answers0