private void refreshDaySteps(DBHandler db, PieChart pieChart, Calendar day, GBDevice device) { ActivityAnalysis analysis = new ActivityAnalysis(); int totalSteps = analysis.calculateTotalSteps(getSamplesOfDay(db, day, device)); pieChart.setCenterText(NumberFormat.getNumberInstance(mLocale).format(totalSteps)); PieData data = new PieData(); List<Entry> entries = new ArrayList<>(); List<Integer> colors = new ArrayList<>(); entries.add(new Entry(totalSteps, 0)); colors.add(akActivity.color); // we don't want labels on the pie chart data.addXValue(""); if (totalSteps < mTargetSteps) { entries.add(new Entry((mTargetSteps - totalSteps), 1)); colors.add(Color.GRAY); // we don't want labels on the pie chart data.addXValue(""); } PieDataSet set = new PieDataSet(entries, ""); set.setColors(colors); data.setDataSet(set); // this hides the values (numeric) added to the set. These would be shown aside the strings set // with addXValue above data.setDrawValues(false); pieChart.setData(data); pieChart.getLegend().setEnabled(false); }
private void refreshWeekBeforeSteps( DBHandler db, BarLineChartBase barChart, Calendar day, GBDevice device) { ActivityAnalysis analysis = new ActivityAnalysis(); day = (Calendar) day.clone(); // do not modify the caller's argument day.add(Calendar.DATE, -7); List<BarEntry> entries = new ArrayList<>(); List<String> labels = new ArrayList<>(); for (int counter = 0; counter < 7; counter++) { entries.add( new BarEntry(analysis.calculateTotalSteps(getSamplesOfDay(db, day, device)), counter)); labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale)); day.add(Calendar.DATE, 1); } BarDataSet set = new BarDataSet(entries, ""); set.setColor(akActivity.color); BarData data = new BarData(labels, set); data.setValueTextColor( Color .GRAY); // prevent tearing other graph elements with the black text. Another approach // would be to hide the values cmpletely with data.setDrawValues(false); LimitLine target = new LimitLine(mTargetSteps); barChart.getAxisLeft().getLimitLines().clear(); barChart.getAxisLeft().addLimitLine(target); setupLegend(barChart); barChart.setData(data); barChart.getLegend().setEnabled(false); }