我在我的Android应用程序中有这个水平条形图,我正在使用mp android图表库。问题是我需要使文本重叠不在后面的栏 这是我目前的条形图
这就是我创建图表的方式
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);
答案 0 :(得分:2)
请添加:
mChart.setDrawValueAboveBar(false);
它会在栏内显示价值。
答案 1 :(得分:0)
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);