setVisibleXRange() not working
I have Bar graph. It MUST display 8 bars. What I have tried but not get desire output. Please have look below code.
protected String[] mMonths = new String[] { "19/03/2015", "18/03/2015",
"17/03/2015", "16/03/2015", "15/03/2015", "14/03/2015",
"13/03/2015", "12/03/2015" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setDrawBarShadow(true);
mChart.setDrawValueAboveBar(true);
mChart.setDescription("");
mChart.setTouchEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setMaxVisibleValueCount(8);
mChart.setPinchZoom(false);
mChart.setDrawBarShadow(false);
mChart.setDrawGridBackground(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setSpaceBetweenLabels(2);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setLabelCount(8);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setLabelCount(8);
setData(8, 50);
}
private void setData(int count, float range) {
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < count; i++) {
xVals.add(mMonths[i % 12]);
}
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < count; i++) {
float mult = (range + 1);
float val = (float) (Math.random() * mult);
yVals1.add(new BarEntry(val, i));
}
BarDataSet set1 = new BarDataSet(yVals1, "Sale");
set1.setColor(Color.rgb(247, 90, 83));
ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
mChart.setData(data);
mChart.setVisibleXRange(8);
Legend l = mChart.getLegend();
l.setPosition(LegendPosition.BELOW_CHART_CENTER);
l.setForm(LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
}

All dates are not displaying. I need to display all the dates anyhow or bar graph need to be scrollable so that all the value can display.
Thanks
In order to display all x-axis values you can do the following:
- reduce the text size of your x-axis labels
- reduce the length of your x-axis labels (e.g. 19/03/15 instead of 19/03/2015)
- call
xAxis.setSpaceBetweenLabels(0)
@PhilJay Thank you for your prompt response ... It works perfect. Is it possible to display the date as it (means 19/03/2015) and chart is scrolling. Same code scrolling for 2 dataSet.
Hi @PhilJay... is there any way to wrap words because i have categories name such as "Groceries & Medicine" in xAxis...