I use the compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' library compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'

How to make the data output integer without a comma.

  // in this example, a LineChart is initialized from xml BarChart chart = (BarChart) view.findViewById(R.id.chart); List<BarEntry> entries = new ArrayList<>(); entries.add(new BarEntry(0, 30)); entries.add(new BarEntry(1, 80)); entries.add(new BarEntry(2, 60)); entries.add(new BarEntry(3, 50)); entries.add(new BarEntry(4, 70)); entries.add(new BarEntry(5, 60)); entries.add(new BarEntry(6, 60)); entries.add(new BarEntry(7, 60)); entries.add(new BarEntry(8, 60)); entries.add(new BarEntry(9, 60)); BarDataSet set = new BarDataSet(entries, "BarDataSet"); set.setColor(Color.parseColor("#FF8000")); chart.setDrawValueAboveBar(true); BarData data = new BarData(set); data.setBarWidth(0.8f); // set custom bar width chart.setData(data); chart.setFitBars(true); // make the x-axis fit exactly all bars chart.invalidate(); // refresh String[] values = new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; XAxis xAxis = chart.getXAxis(); xAxis.setValueFormatter(new MyXAxisValueFormatter(values)); xAxis.setGranularity(1); xAxis.setGranularityEnabled(true); xAxis.setLabelCount(10); chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM); return view; } public static Fragment_infografika_lvl newInstance() { return new Fragment_infografika_lvl(); } public class MyXAxisValueFormatter implements IAxisValueFormatter { private String[] mValues; public MyXAxisValueFormatter(String[] values) { this.mValues = values; } @Override public String getFormattedValue(float value, AxisBase axis) { // "value" represents the position of the label on the axis (x or y) return mValues[(int) value]; } } 

enter image description here

    1 answer 1

    From the documentation

     public class MyValueFormatter implements IValueFormatter { private DecimalFormat mFormat; public MyValueFormatter() { mFormat = new DecimalFormat("###,###,##0.0"); // use one decimal } @Override public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) { // write your logic here return mFormat.format(value) + " $"; // eg append a dollar-sign } } 

    In your case, mFormat = new DecimalFormat("####"); and do not add a dollar

    DecimalFormat

    • It works for tags that are on the side and bottom. But for some reason for the values ​​of the columns it is impossible to do - Vitaly Robinovsky
    • This is because you use IAxisValueFormatter, and I wrote to you about IValueFormatter - rjhdby
    • thanks, for some reason I didn’t pay attention to this)) it turned out to be not attentive - Vitaly Robinovsky