0

I have values like integer or date value but don't know where to use them in Android.

So that when I zoom in the values remain at the same place and between the values there is an empty space.

I want to show the values between them like [1 2 3] on graph only showing values 1,2,3 but not showing like 1,1.1,1.2,1.3 ... 2.8 2.9(when zooming in)?

final ArrayList<String> xLabel = new ArrayList<>();
    xLabel.add("1");
    xLabel.add("2");
    xLabel.add("3");
    xLabel.add("4");
    xLabel.add("5");
    xLabel.add("6");
XAxis xAxis = line.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f); // only intervals of 1 day
    xAxis.setValueFormatter(xAxisFormatter);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return xLabel.get((int)value);
        }
    });
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

1

Enable the granularity and add the interval for it like

XAxis xAxis = mBarChart.getAxisLeft();
xAxis.setGranularity(0.1f);
xAxis.setGranularityEnabled(true);

In your case the interval is 0.1

Kashif K.
  • 88
  • 1
  • 9
0

Set xAxis granularity to 1:

private void setXAxisGranularity(Chart chart)
{
    XAxis xAxis = chart.getXAxis();
    xAxis.setGranularityEnabled(true);
    xAxis.setGranularity(1f);
}
Ayaz Alifov
  • 8,334
  • 4
  • 61
  • 56