0
我有一個條形圖,其中有4個條形,使用MPAndroidChart library分組成2個組。 這個工程到目前爲止。現在我想在每個組上面顯示一個標題。這是我當前的輸出(如您所見,標題未顯示在每個組上方)。MPAndroidChart分組條形圖:組標題未顯示在組上
我的代碼:
_overviewBarChart.setPinchZoom(false);
_overviewBarChart.getDescription().setEnabled(false);
_overviewBarChart.setDrawValueAboveBar(true);
_overviewBarChart.getXAxis().setCenterAxisLabels(true);
_overviewBarChart.getXAxis().setAxisMinimum(0);
_overviewBarChart.getXAxis().setDrawGridLines(false);
private void updateOverviewBarChart() {
//Init calorie needs bars
BarEntry todayCalorieNeedsBarEntry = new BarEntry(0, _calorieEntry.getTarget());
BarEntry yesterdayCalorieNeedsBarEntry = new BarEntry(0, 0);
if (_yesterdayCalorieEntry != null)
yesterdayCalorieNeedsBarEntry = new BarEntry(0, _yesterdayCalorieEntry.getTarget());
ArrayList<BarEntry> calorieNeedsBarEntries = new ArrayList<>();
calorieNeedsBarEntries.add(todayCalorieNeedsBarEntry);
calorieNeedsBarEntries.add(yesterdayCalorieNeedsBarEntry);
//Init consumed calories bars
BarEntry todayConsumedCaloriesBarEntry = new BarEntry(1, _calorieEntry.getConsumed());
BarEntry yesterdayConsumedCaloriesBarEntry = new BarEntry(1, 0);
if (_yesterdayCalorieEntry != null)
yesterdayConsumedCaloriesBarEntry = new BarEntry(1, _yesterdayCalorieEntry.getConsumed());
ArrayList<BarEntry> consumedCaloriesBarEntries = new ArrayList<>();
consumedCaloriesBarEntries.add(todayConsumedCaloriesBarEntry);
consumedCaloriesBarEntries.add(yesterdayConsumedCaloriesBarEntry);
//Init BarDataSets
BarDataSet calorieNeedsBarDataSet = new BarDataSet(calorieNeedsBarEntries, getString(R.string.fragment_main_calorieneeds));
calorieNeedsBarDataSet.setColor(Color.parseColor("#26A69A"));
BarDataSet consumedCaloriesBarDataSet = new BarDataSet(consumedCaloriesBarEntries, getString(R.string.fragment_main_consumed));
consumedCaloriesBarDataSet.setColor(Color.parseColor("#E53935"));
//Init BarData, group BarEntrys, set group titles
BarData barData = new BarData(calorieNeedsBarDataSet, consumedCaloriesBarDataSet);
barData.setValueTextSize(14);
barData.setBarWidth(0.2f);
barData.groupBars(0, 0.15f, 0.1f);
ArrayList<String> groupTitles = new ArrayList<String>();
groupTitles.add(getString(R.string.fragment_main_today));
groupTitles.add(getString(R.string.fragment_main_yesterday));
_overviewBarChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(groupTitles));// new BarChartStringFormatter(groupTitles));
//Set data, redraw BarChart
_overviewBarChart.setData(barData);
_overviewBarChart.invalidate();
}
你可以看到我做錯了嗎?