如何在MPAndroidChart的onValueSelected()中获取Entry的选定标签?

问题描述:

我为饼图写了以下OnChartValueSelectedListener.我可以使用下面的代码获取值.但是,我也希望获得文本标签.在下面的代码中,e.getY()将获得y值.如何获取Entry的文本标签?

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() {

        }
    });

Entry转换为PieEntry,然后使用方法getLabel().

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());
}