2
votes

I'm new at using MPAndroidChart and I'm stuck with this problem. When I draw a PieChart with my values and highlight one of the slices, the color of the other slices disappear. This is the pie chart before selecting a slice(I cannot post pictures because I just created an account):

http://s27.postimg.org/6ijte280j/Screenshot_2015_03_09_11_27_19.png

And this is the pie Chart when I select slice below("Ruben"):

http://s7.postimg.org/60bwczpyz/Screenshot_2015_03_09_11_27_33.png

The slice "Ruben" is highlighted and the background of the other dissapear.

This is the method that creates the pieChart:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_display_pie_chart);

    mChart = (PieChart) findViewById(R.id.chart1);
    mChart.setHoleColorTransparent(true);

    mChart.setHoleRadius(60f);

    mChart.setDrawCenterText(true);

    mChart.setDrawHoleEnabled(true);

    mChart.setRotationAngle(0);

    mChart.setRotationEnabled(true);

     mChart.setOnChartValueSelectedListener(this);

     mChart.setCenterText("Test Graph");

     ArrayList<Entry> yVals1 = new ArrayList<Entry>();

     yVals1.add(new Entry((float) 20.0, yVals1.size()-1));
     yVals1.add(new Entry((float) 30.0, yVals1.size()-1));

     ArrayList<String> xVals = new ArrayList<String>();

     xVals.add("Ruben");
     xVals.add("Claudio");

     PieDataSet dataSet = new PieDataSet(yVals1, "Idades Porlande");
     dataSet.setSliceSpace(3f);

     PieData data = new PieData(xVals, dataSet);
     mChart.setData(data);
    }

What you guys think is the problem?

Regards.

1
mChart.setOnChartValueSelectedListener(); is this working @Ruben - Praneeth

1 Answers

4
votes

The problem is with the below lines

 yVals1.add(new Entry((float) 20.0, yVals1.size()-1));
 yVals1.add(new Entry((float) 30.0, yVals1.size()-1));

here, in constructor Entry(float val, int xIndex), xIndex starts from 0,1,2.. so on.

So change the index values that you have given.

yVals1.add(new Entry((float) 20.0, 0));
yVals1.add(new Entry((float) 30.0, 1));