Prathmesh Patil Prathmesh Patil - 4 months ago 31
Android Question

Getting error at PieData data = new PieData(labels, dataset); while adding data

In my app there is a need of pie chart for which i am using MPAndroidChart but, getting error while adding data in Piedata constructor,please help.
Using dependancy compile 'com.github.PhilJay:MPAndroidChart:v3.0.0 beta'

imageView=(PieChart) v.findViewById(R.id.result_text);
ArrayList<Entry> entries = new ArrayList<>();
entries.add(new Entry(4f, 0));
entries.add(new Entry(8f, 1));
entries.add(new Entry(6f, 2));
entries.add(new Entry(12f, 3));
entries.add(new Entry(18f, 4));
entries.add(new Entry(9f, 5));
PieDataSet dataset = new PieDataSet(entries,"uyggh");
ArrayList<Object> labels = new ArrayList<Object>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
PieData data = new PieData(labels, dataset);//getting error here
imageView.setData(data);
imageView.setDescription("Description");

Answer

PieData takes only one argument and that is PieDataSet. So replace

PieData data = new PieData(labels, dataset);

with

PieData data = new PieData(dataset);

For more details, you can check this official example.

Hope, this answer is helpful to you.