Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected label for Entry inside onValueSelected() in MPAndroidChart?

I have written the following OnChartValueSelectedListener for my pie chart. I am able to get the value with the code below. However, I would like to get the text label as well. In the code below, e.getY() will get the y-value. How do I get the text label for the Entry?

holder.chartyear.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, Highlight h) {
            Log.e("VAL SELECTED", "Value: " + e.getY() + ", index: " + h.getX()
                            + ", DataSet index: ");
        }

        @Override
        public void onNothingSelected() {

        }
    });
like image 841
anonymous Avatar asked Dec 22 '16 12:12

anonymous


1 Answers

Cast the Entry as a PieEntry and then use the method getLabel().

@Override 
public void onValueSelected(Entry e, Highlight h) {
    PieEntry pe = (PieEntry) e;
    Log.e("LABEL",pe.getLabel());
}
like image 62
anonymous Avatar answered Oct 14 '22 21:10

anonymous