Y轴标签未显示在Android Horizo​​ntalBarChart MPAndroidChart中

时间:2019-09-08 03:48:45

标签: android mpandroidchart

无法在 Horizo​​ntalBarChart MPAndroidChart中看到所有y标签。

它仅显示1个标签,但应该显示4个标签。

dayList 的大小为4,表示有4个条目。

问题:

  • 不显示y标签
  • 未显示每条线的值

enter image description here

horizontalBarChart.setDrawBarShadow(false);
horizontalBarChart.setDrawValueAboveBar(true);
horizontalBarChart.getDescription().setEnabled(false);

// scaling can now only be done on x- and y-axis separately
horizontalBarChart.setPinchZoom(false);

horizontalBarChart.setDrawGridBackground(false);

horizontalBarChart.setFitBars(true);

Legend l = horizontalBarChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);

l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setFormSize(16f);
l.setXEntrySpace(4f);

ArrayList<BarEntry> values = new ArrayList<>();
List<String> dayList = new ArrayList<>();
List<DayWisePayment> dayWisePaymentList = dayWisePaymentStatistics.getData();

int i = 0;
for (DayWisePayment obj :  dayWisePaymentList) {
     values.add(new BarEntry(i * 10f, (float) obj.getSum()));
     dayList.add(obj.getPaymentDoneAt());
     i++;
}

XAxis xAxis = horizontalBarChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new IndexAxisValueFormatter(dayList));

// horizontalBarChart.getAxisLeft().setAxisMinimum(0);
xAxis.setGranularity(1);
xAxis.setCenterAxisLabels(false);
xAxis.setGranularityEnabled(true);

BarDataSet set1 = new BarDataSet(values, dayWisePaymentStatistics.getTitle());
set1.setDrawIcons(false);

ArrayList<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add(set1);

BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setBarWidth(9f);

horizontalBarChart.setExtraOffsets(0f, 0f, 0f, 20f);
horizontalBarChart.setData(data);

0 个答案:

没有答案