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

為{幸葍}努か 提交于 2019-12-06 11:24:27

问题


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

        }
    });

回答1:


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


来源:https://stackoverflow.com/questions/41283022/how-to-get-selected-label-for-entry-inside-onvalueselected-in-mpandroidchart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!