use of com.github.mikephil.charting.formatter.IndexAxisValueFormatter in project android by lucadln.
the class ScoreChart method disposeHorizontalBarChart.
/**
* Method to set data and design for the bar chart
*/
public void disposeHorizontalBarChart(float[] scores, int[] correctConjugationsCount, int[] totalConjugationsCount) {
/* Set a custom renderer. This helps to show chart labels either
* inside or outside the chart bars depending on their values */
barChart.setRenderer(new CustomHorizontalBarChartRenderer(barChart, barChart.getAnimator(), barChart.getViewPortHandler(), scores));
barChart.invalidate();
// Add entry values for every tense
ArrayList<BarEntry> barEntries = new ArrayList<>();
for (int i = 0; i < tenses.length; i++) {
barEntries.add(new BarEntry((float) i, scores[i]));
}
// Create a data set from the entry values
BarDataSet dataSet = new BarDataSet(barEntries, "Tenses");
// Set data set values to be visible on the graph
dataSet.setDrawValues(true);
// Create a data object from the data set
BarData data = new BarData(dataSet);
// Set the width of the bars
data.setBarWidth(0.68f);
// Make the chart use the acquired data
barChart.setData(data);
// Display data as <correctAnswers>/<totalAnswers>
data.setValueFormatter(new CustomValueFormatter(correctConjugationsCount, totalConjugationsCount));
// Create explanation labels for each bar
final ArrayList<String> barLabels = new ArrayList<>();
barLabels.add("Present");
barLabels.add("Pres. Perfect");
barLabels.add("Simple Past");
barLabels.add("Past Perfect");
barLabels.add("Conditional");
barLabels.add("Cond. Perfect");
barLabels.add("Future");
// Display explanation labels
barChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(barLabels));
// Set the minimum and maximum bar values
barChart.getAxisLeft().setAxisMaximum(100);
barChart.getAxisLeft().setAxisMinimum(0);
// Set a color for each bar in the chart based on its value
setBarChartColors(scores);
// Animate chart so that bars are sliding from left to right
barChart.animateXY(1000, 1000);
// Hide grid lines
barChart.getAxisLeft().setEnabled(false);
barChart.getAxisRight().setEnabled(false);
// Hide graph description
barChart.getDescription().setEnabled(false);
// Hide graph legend
barChart.getLegend().setEnabled(false);
// Set colors and font style
dataSet.setColors(colors);
data.setValueTextSize(13f);
data.setValueTextColor(Color.DKGRAY);
}
Aggregations