-
-
Save jezinka/266b8a7032b677319f5c7013616524aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void createDinnerBarChart() { | |
| dbHelper = new CoNaObiadDbHelper(this); | |
| DinnerContract dinnerContract = new DinnerContract(); | |
| LinkedHashMap<String, Long> mealData = dinnerContract.getDinnerStatistics(dbHelper); | |
| List<BarEntry> entries = new ArrayList<>(); | |
| int i = 0; | |
| for (Map.Entry<String, Long> entry : mealData.entrySet()) { | |
| String mealName = entry.getKey(); | |
| Long quantity = entry.getValue(); | |
| entries.add(new BarEntry(i, quantity, mealName)); | |
| i++; | |
| } | |
| final BarDataSet set = new BarDataSet(entries, ""); | |
| BarData data = new BarData(set); | |
| data.setBarWidth(0.2f); | |
| HorizontalBarChart chart = (HorizontalBarChart) findViewById(R.id.chart); | |
| chart.getLegend().setEnabled(false); | |
| chart.getDescription().setEnabled(false); | |
| XAxis xAxis = chart.getXAxis(); | |
| xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | |
| xAxis.setGranularity(1f); | |
| xAxis.setLabelCount(i); | |
| xAxis.setDrawGridLines(false); | |
| xAxis.setValueFormatter(new IAxisValueFormatter() { | |
| @Override | |
| public String getFormattedValue(float value, AxisBase axis) { | |
| return (String) set.getEntryForXValue(value, 0.1f).getData(); | |
| } | |
| }); | |
| YAxis yAxis = chart.getAxisLeft(); | |
| yAxis.setGranularity(0.5f); | |
| chart.getAxisRight().setDrawLabels(false); | |
| chart.getAxisRight().setDrawGridLines(false); | |
| chart.setData(data); | |
| chart.setVisibleXRange(0,i); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment