How to display all x-axis value align with group bar in mpchart android

  • its because of the bar space and group space, needed to change the width correctly and set setVisibleXRangeMaximum to 6. You can try this,hope this helps

    String[] days = new String[]{"TYPE 1", "TYPE 2", "TYPE 3", "TYPE 4", "TYPE 5", "TYPE 6"};
    
          ArrayList<BarEntry> barEntries = new ArrayList<>();
          ArrayList<BarEntry> barEntries2 = new ArrayList<>();
    
          barEntries.add(new BarEntry(1,50f));
          barEntries.add(new BarEntry(2,42f));
          barEntries.add(new BarEntry(3,34f));
          barEntries.add(new BarEntry(4,24f));
          barEntries.add(new BarEntry(5,50f));
          barEntries.add(new BarEntry(6,42f));
    
          barEntries2.add(new BarEntry(1,17f));
          barEntries2.add(new BarEntry(2,19f));
          barEntries2.add(new BarEntry(3,19f));
          barEntries2.add(new BarEntry(4,18f));
          barEntries2.add(new BarEntry(5,17f));
          barEntries2.add(new BarEntry(6,19f));
    
          BarDataSet barDataSet = new BarDataSet(barEntries,"");
          barDataSet.setColor(Color.parseColor("#F44336"));
    
          BarDataSet barDataSet1 = new BarDataSet(barEntries2,"");
          barDataSet1.setColors(Color.parseColor("#9C27B0"));
    
          BarData data = new BarData(barDataSet,barDataSet1);
          chart7.setData(data);
    
          chart7.setDrawBarShadow(false);
          chart7.setDrawValueAboveBar(true);
          chart7.setMaxVisibleValueCount(50);
          chart7.setPinchZoom(false);
          chart7.setDrawGridBackground(false);
          chart7.getDescription().setEnabled(false);
          Legend l = chart7.getLegend();
          l.setEnabled(false);
    
          XAxis xAxis = chart7.getXAxis();
          xAxis.setValueFormatter(new IndexAxisValueFormatter(days));
          xAxis.setCenterAxisLabels(true);
          xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
          xAxis.setGranularity(1);
          xAxis.setGranularityEnabled(true);
          chart7.setDragEnabled(true);
          chart7.setVisibleXRangeMaximum(6);
          float barSpace = 0.02f;
          float groupSpace = 0.55f;
          data.setBarWidth(0.20f);
          chart7.getXAxis().setAxisMinimum(0);
          chart7.getXAxis().setAxisMaximum(6f);
          chart7.groupBars(0, groupSpace, barSpace);
    

enter image description here