Reputation: 772
I have this horizontal bar chart in my android app, i am using mp android chart library. The problem is i need to make the text overlap the bars not behind this is my current bar chart
and this is how i created my chart
BarDataSet dataset = new BarDataSet(entries, "");
ArrayList<String> array = new ArrayList<String>();
for (int i = 0; i < poll.getQuestions().get(0).getAnswers().size(); i++)
array.add(poll.getQuestions().get(0).getAnswers().get(i).getAnswer());
BarData data = new BarData(array, dataset);
dataset.setColor(ContextCompat.getColor(PollDetailActivity.this, R.color.green)); //
mChart.setDescription("");
mChart.getAxisLeft().setDrawLabels(false);
mChart.getAxisRight().setDrawLabels(false);
mChart.getAxisLeft().setDrawGridLines(false);
mChart.getXAxis().setDrawGridLines(false);
// pieChart.getAx().setDrawLabels(false);
mChart.setData(data);
mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
// pieChart.getXAxis().setEnabled(false);
mChart.getAxisRight().setEnabled(false);
mChart.animateY(5000);
Upvotes: 0
Views: 1264
Reputation: 3189
HorizontalBarChart barChart= (HorizontalBarChart) findViewById(R.id.chart);
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(4f, 0));
entries.add(new BarEntry(8f, 1));
entries.add(new BarEntry(6f, 2));
entries.add(new BarEntry(12f, 3));
entries.add(new BarEntry(18f, 4));
entries.add(new BarEntry(9f, 5));
BarDataSet dataset = new BarDataSet(entries, "# of Calls");
dataset.setBarSpacePercent(35f);
ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
BarData data = new BarData(labels, dataset);
data.setValueTextSize(20f);
data.setDrawValues(true);
barChart.setData(data);
barChart.animateY(5000);
barChart.setDrawValueAboveBar(false);
Upvotes: 0
Reputation: 159
please add:
mChart.setDrawValueAboveBar(false);
it will show value inside bar.
Upvotes: 2