I am using MPAndroidChart and I am trying to create a pie chart that looks like a donut using mpandroidchart lib, but somehow i am unable to do that.
Below is my code-
ArrayList<Entry> entries = new ArrayList<>();
entries.add(new Entry((float) 20.0, 0));
entries.add(new Entry((float) 30.0, 1));
int colors[] = {Color.parseColor("#DCDEE0"),Color.parseColor("#466A80"),Color.parseColor("#0078CA"),Color.parseColor("#5BC2E7"),Color.parseColor("#99E4FF")};
PieDataSet dataset = new PieDataSet(entries, "# of Calls");
dataset.setColors(colors);
dataset.setSliceSpace(3f);
ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
/* labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");*/
PieChart chart1 = new PieChart(this);
chart1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.5f));
chart1.setHoleRadius(60f);
chart1.setHoleColorTransparent(false);
chart1.setDrawHoleEnabled(true);
chart1.setUsePercentValues(true);
chart1.setHoleColor(Color.WHITE);
PieChart chart2 = new PieChart(this);
chart2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.5f));
LinearLayout chart = (LinearLayout)findViewById(R.id.chart);
chart.addView(chart1);
chart.addView(chart2);
PieData data = new PieData(labels, dataset);
chart1.setData(data);
chart2.setData(data);
I am able to draw pie chart but can't make it look like a donut.Please refer the attached screen shot. Can someone please help.
Best Answer
This is a known issue that has been fixed in the latest commit. https://github.com/PhilJay/MPAndroidChart/issues/527
The v2.1.0 of the library that will contain the fix should be out within the next week!