I want to show 3 several pie charts on the same layout. I insert different data sets to different charts, but by the end all of these data shows on 1 chart and another 2 charts have no data. Could there be a problem that I cannot create several charts on one layout?
private PieChart firstCh, secondCh, thirdCh;
private void openDialog() {
//code with dialog
firstCh = dialogStat.findViewById(R.id.firstCharacter);
secondCh = dialogStat.findViewById(R.id.secondCharacter);
thirdCh = dialogStat.findViewById(R.id.thirdCharacter);
ArrayList<PieEntry> statForFirst = new ArrayList<>();
statForFirst.add(new PieEntry(myNumber, "Kiss"));
statForFirst.add(new PieEntry(myNumber, "Marry"));
statForFirst.add(new PieEntry(myNumber, "Kill"));
ArrayList<PieEntry> statForSecond = new ArrayList<>();
statForFirst.add(new PieEntry(myNumber, "Kiss"));
statForFirst.add(new PieEntry(myNumber, "Marry"));
statForFirst.add(new PieEntry(myNumber, "Kill"));
ArrayList<PieEntry> statForThird = new ArrayList<>();
statForFirst.add(new PieEntry(myNumber, "Kiss"));
statForFirst.add(new PieEntry(myNumber, "Marry"));
statForFirst.add(new PieEntry(myNumber, "Kill"));
setNewChart(firstCh, statForFirst);
setNewChart(secondCh, statForSecond);
setNewChart(thirdCh, statForThird);
//code with dialog
}
private void setNewChart(PieChart chart, ArrayList<PieEntry> entries) {
chart.getDescription().setEnabled(false);
chart.getLegend().setEnabled(false);
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setColors(getResources().getColor(R.color.pinkySarah), getResources().getColor(R.color.lightViola), getResources().getColor(R.color.eyeKiller));
PieData data = new PieData(dataSet);
data.setDrawValues(true);
data.setValueFormatter(new PercentFormatter(chart));
data.setValueTextSize(10f);
data.setValueTextColor(R.color.darkViola);
chart.setData(data);
chart.invalidate();
}
This is how it looks in my app For reference, i am using LinearLayout
CodePudding user response:
Just a typo mistake.
you have added all the data to statForFirst arraylist instead of other two lists. Fix this and you are good to go