【发布时间】:2018-07-02 01:49:31
【问题描述】:
我正在使用 MPAndroid 库。 实施 'com.github.PhilJay:MPAndroidChart:v3.0.3' 我需要用标签创建条形图。 我的代码如下,但它不起作用: 这是要显示的条形数组。
public ArrayList<BarEntry> getBarEntryArrayList() {
ArrayList<BarEntry> barEntries = new ArrayList<BarEntry>();
barEntries.add(new BarEntry(2f, 0));
barEntries.add(new BarEntry(4f, 1));
barEntries.add(new BarEntry(6f, 2));
barEntries.add(new BarEntry(8f, 3));
barEntries.add(new BarEntry(7f, 4));
barEntries.add(new BarEntry(3f, 5));
return barEntries;
}
这是显示在底部的标签数组。
public ArrayList<String> getBarEntryLabels() {
ArrayList<String> BarEntryLabels = new ArrayList<String>();
BarEntryLabels.add("J");
BarEntryLabels.add("F");
BarEntryLabels.add("M");
BarEntryLabels.add("A");
BarEntryLabels.add("M");
BarEntryLabels.add("J");
BarEntryLabels.add("J");
BarEntryLabels.add("A");
BarEntryLabels.add("S");
BarEntryLabels.add("O");
BarEntryLabels.add("N");
BarEntryLabels.add("D");
return BarEntryLabels;
}
标签数组和入口数组设置问题
private void setBarChartData() {
BarDataSet barDataSet = new BarDataSet(getBarEntryArrayList(), getBarEntryLabels() );
barDataSet.setColors(ColorTemplate.COLORFUL_COLORS);
BarData barData = new BarData(barDataSet);
barChart.setData(barData);
barChart.animateY(3000);
}
这条线不工作。
BarDataSet barDataSet = new BarDataSet(getBarEntryArrayList(), getBarEntryLabels() );
如果制作没有标签的代码,它就可以工作。
BarDataSet barDataSet = new BarDataSet(getBarEntryArrayList(), "Dummy text" );
我必须使用标签数组。 提前致谢。
我需要像这样创建图表。 请帮帮我。
【问题讨论】:
-
哥们,您想要 xAxis 上的标签或作为条形上方或内部条形上的值吗?
标签: java android char mpandroidchart