Search code examples
androidplot

Androidplot - Format PointLabel (remove decimals) on Bar Graph


I have been searching for how to format the text (remove decimals) of point labels on Bar graph. This is my code:

BarFormatter bf = new BarFormatter(Color.CYAN,Color.CYAN);
    PointLabelFormatter plf = new PointLabelFormatter();
    plf.getTextPaint().setColor(Color.BLUE);
    bf.setPointLabelFormatter(plf);

i can only set the color here. The label is displayed with decimals. How to remove it or set a decimal format in this? This comment https://stackoverflow.com/a/39482297/9969285 here describes pointlabeler under lineandpointformatter. How to implement this for a bar graph?


Solution

  • Should be the same as what you linked - BarFormatter extends LineAndPointFormatter:

    bf.setPointLabeler(new PointLabeler<XYSeries>() {
        final DecimalFormat df = new DecimalFormat("#");
    
        @Override
        public String getLabel(XYSeries series, int index) {
            return df.format(series.getY(index));
        }
    });