我正在开发一个项目,我必须以图形表示方式显示数据。为此,我使用的是Mpchart库。根据我的项目要求,我必须根据条形码显示相同索引上的每个酒吧栏,但它正在成为我不想要的堆叠条形图。
例如: -
ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
// for create Grouped Bar chart
ArrayList<BarEntry> group1 = new ArrayList<>();
group1.add(new BarEntry(1f, 0));
group1.add(new BarEntry(8f, 0));
group1.add(new BarEntry(1f, 0));
group1.add(new BarEntry(1f, 0));
ArrayList<BarEntry> group2 = new ArrayList<>();
group2.add(new BarEntry(2f, 1));
group2.add(new BarEntry(2f, 1));
group2.add(new BarEntry(2f, 1));
group2.add(new BarEntry(2f, 1));
ArrayList<BarEntry> group3 = new ArrayList<>();
group3.add(new BarEntry(3f, 2));
group3.add(new BarEntry(3f, 2));
group3.add(new BarEntry(3f, 2));
group3.add(new BarEntry(3f, 2));
ArrayList<BarEntry> group4 = new ArrayList<>();
group4.add(new BarEntry(4f, 3));
group4.add(new BarEntry(4f, 3));
group4.add(new BarEntry(4f, 3));
group4.add(new BarEntry(4f, 3));
ArrayList<BarEntry> group5 = new ArrayList<>();
group5.add(new BarEntry(5f, 4));
group5.add(new BarEntry(5f, 4));
group5.add(new BarEntry(5f, 4));
group5.add(new BarEntry(5f, 4));
ArrayList<BarEntry> group6 = new ArrayList<>();
group6.add(new BarEntry(6f, 5));
group6.add(new BarEntry(6f, 5));
group6.add(new BarEntry(6f, 5));
group6.add(new BarEntry(6f, 5));
ArrayList<BarEntry> group7 = new ArrayList<>();
group7.add(new BarEntry(7f, 6));
group7.add(new BarEntry(7f, 6));
group7.add(new BarEntry(7f, 6));
group7.add(new BarEntry(7f, 6));
ArrayList<BarEntry> group8 = new ArrayList<>();
group8.add(new BarEntry(8f, 7));
group8.add(new BarEntry(8f, 7));
group8.add(new BarEntry(8f, 7));
group8.add(new BarEntry(8f, 7));
ArrayList<BarEntry> group9 = new ArrayList<>();
group9.add(new BarEntry(9f, 8));
group9.add(new BarEntry(9f, 8));
group9.add(new BarEntry(9f, 8));
group9.add(new BarEntry(9f, 8));
ArrayList<BarEntry> group10 = new ArrayList<>();
group10.add(new BarEntry(10f, 9));
group10.add(new BarEntry(10f, 9));
group10.add(new BarEntry(10f, 9));
group10.add(new BarEntry(10f, 9));
BarDataSet barDataSet1 = new BarDataSet(group1, "Group 1");
barDataSet1.setColors(ColorTemplate.COLORFUL_COLORS);
barChart.isTransitionGroup();
BarDataSet barDataSet2 = new BarDataSet(group2, "Group 2");
barDataSet2.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet3 = new BarDataSet(group3, "Group 3");
barDataSet3.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet4 = new BarDataSet(group4, "Group 4");
barDataSet4.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet5 = new BarDataSet(group5, "Group 5");
barDataSet5.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet6 = new BarDataSet(group6, "Group 6");
barDataSet6.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet7 = new BarDataSet(group7, "Group 7");
barDataSet7.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet8 = new BarDataSet(group8, "Group 8");
barDataSet8.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet9 = new BarDataSet(group9, "Group 9");
barDataSet9.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet10 = new BarDataSet(group10, "Group 10");
barDataSet10.setColors(ColorTemplate.COLORFUL_COLORS);
它会使条形图铆接并且相同的索引条彼此重叠。
如何并排显示它们。
我正在使用库Mpchart 2.1.6版
提前感谢。
答案 0 :(得分:0)
我使用的是2.1.6版本。按照给出的例子:
BarChart barChart = (BarChart) findViewById(R.id.chart);
ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
//for create Grouped Bar chart
ArrayList<BarEntry> group1 = new ArrayList<>();
group1.add(new BarEntry(4f, 0));
group1.add(new BarEntry(8f, 1));
group1.add(new BarEntry(6f, 2));
group1.add(new BarEntry(12f, 3));
group1.add(new BarEntry(18f, 4));
group1.add(new BarEntry(9f, 5));
ArrayList<BarEntry> group2 = new ArrayList<>();
group2.add(new BarEntry(6f, 0));
group2.add(new BarEntry(7f, 1));
group2.add(new BarEntry(8f, 2));
group2.add(new BarEntry(12f, 3));
group2.add(new BarEntry(15f, 4));
group2.add(new BarEntry(10f, 5));
BarDataSet barDataSet1 = new BarDataSet(group1, "Group 1");
barDataSet1.setColors(ColorTemplate.COLORFUL_COLORS);
BarDataSet barDataSet2 = new BarDataSet(group2, "Group 2");
barDataSet2.setColors(ColorTemplate.COLORFUL_COLORS);
ArrayList<BarDataSet> dataset = new ArrayList<>();
dataset.add(barDataSet1);
dataset.add(barDataSet2);
BarData data = new BarData(labels, dataset);
barChart.setData(data);
barChart.animateY(5000);
barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);