private void setChartData(ClimbingArea ClimbingArea) { HashMap<Integer, Integer> difficultyMap = new HashMap<>(); for (int i = AppConstants.MIN_UIAA_LEVEL; i <= AppConstants.MAX_UIAA_LEVEL; ++i) { difficultyMap.put(i, 0); } for (ClimbingRoute route : ClimbingArea.getRoutes()) { String difficulty = route.getUIAARank(); int routeDifficulty = Utils.trimUIAARank(difficulty); if (difficultyMap.containsKey(routeDifficulty)) { difficultyMap.put(routeDifficulty, difficultyMap.get(routeDifficulty) + 1); } } ArrayList<BarEntry> routeDifficulties = new ArrayList<BarEntry>(); String[] xVals = new String[difficultyMap.size()]; List<Integer> orderedList = new ArrayList<>(difficultyMap.keySet()); Collections.sort(orderedList); int indexCounter = 0; for (Integer difficulty : orderedList) { xVals[indexCounter] = difficulty + ""; // BarEntry entry = new BarEntry(difficultyMap.get(difficulty), indexCounter++ , difficulty // +""); BarEntry entry = new BarEntry(difficulty, difficultyMap.get(difficulty), indexCounter++); routeDifficulties.add(entry); } mChart.getXAxis().setLabelCount(xVals.length); BarDataSet set1 = new BarDataSet(routeDifficulties, "Schwierigkeiten"); // set1.setColor(getResources().getColor(R.color.primary_700)); int[] uiaaChartColors = new int[AppConstants.UIAA_CHART_COLORS.length]; for (int i = 0; i < uiaaChartColors.length; ++i) { uiaaChartColors[i] = getResources().getColor(AppConstants.UIAA_CHART_COLORS[i]); } set1.setColors(uiaaChartColors); ArrayList<IBarDataSet> dataSets = new ArrayList<>(); dataSets.add(set1); BarData data = new BarData(dataSets); data.setValueFormatter(new MyValueFormatter()); data.setValueTextSize(10f); mChart.setData(data); mChart.animateX(1000); mChart.animateY(1000); }
@SuppressLint("NewApi") @Override public void onValueSelected(Entry e, Highlight h) { int selectedDifficulty = (int) e.getX(); clearSelectedRoutes(); for (ClimbingRoute route : selectedArea.getRoutes()) { if (Utils.trimUIAARank(route.getUIAARank()) == selectedDifficulty) selectedRoutes.add(route); } // recyclerViewAdapter.notifyItemRangeChanged(0, selectedRoutes.size()); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); recList.invalidate(); if (selectedRoutes.isEmpty()) onNothingSelected(); }