private void displayGraph(){
barChart.setDrawBarShadow(false);
barChart.setDrawValueAboveBar(true);
barChart.setMaxVisibleValueCount(50);
barChart.setPinchZoom(false);
barChart.setDrawGridBackground(false);
barChart.getDescription().setEnabled(false);
Legend l = barChart.getLegend();
l.setEnabled(false);
ArrayList<BarEntry> barEntries = new ArrayList<>();
ArrayList<BarEntry> barEntries1 = 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(1,50f));
barEntries.add(new BarEntry(2,42f));
barEntries1.add(new BarEntry(1,17f));
barEntries1.add(new BarEntry(2,19f));
barEntries1.add(new BarEntry(3,19f));
barEntries1.add(new BarEntry(4,18f));
barEntries1.add(new BarEntry(1,17f));
barEntries1.add(new BarEntry(2,19f));
BarDataSet barDataSet = new BarDataSet(barEntries,"");
barDataSet.setColor(Color.parseColor("#F44336"));
barDataSet.setDrawValues(false);
BarDataSet barDataSet1 = new BarDataSet(barEntries1,"");
barDataSet1.setColors(Color.parseColor("#9C27B0"));
barDataSet1.setDrawValues(false);
String[] months = new String[] {"TYPE 1", "TYPE 2", "TYPE 3", "TYPE 4","TYPE 5","TYPE 6"};
BarData data = new BarData(barDataSet,barDataSet1);
barChart.setData(data);
XAxis xAxis = barChart.getXAxis();
xAxis.setValueFormatter(new IndexAxisValueFormatter(months));
barChart.getAxisLeft().setAxisMinimum(0);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setGranularity(1);
xAxis.setGranularityEnabled(true);
xAxis.setLabelCount(5);
xAxis.setDrawGridLines(false);
xAxis.setAxisMaximum(6);
xAxis.setAvoidFirstLastClipping(true);
float barSpace = 0.02f;
float groupSpace = 0.3f;
int groupCount = 6;
data.setBarWidth(0.15f);
barChart.getXAxis().setAxisMinimum(0);
barChart.getXAxis().setAxisMaximum(0 + barChart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
barChart.groupBars(0, groupSpace, barSpace); // perform the "explicit" grouping
}
这是我的代码,我正在尝试使用 2 个组项和 6 个条形绘制图表,并且我已经定义了 6 种类型的 {"TYPE 1"、"TYPE 2"、"TYPE 3"、"TYPE 4"、"TYPE 5"," TYPE 6"} 值,但是当我尝试运行并看到所有 x 轴值没有打印并且它也没有与组项对齐时显示。
下面是使用给定代码的图表的输出:
虽然我想显示与组栏对齐的所有 x 轴值,但请帮助我在代码中做错了什么。