如何在MPAndroidChart的onValueSelected()中获取Entry的选定标签? [英] How to get selected label for Entry inside onValueSelected() in MPAndroidChart?
本文介绍了如何在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());
}
这篇关于如何在MPAndroidChart的onValueSelected()中获取Entry的选定标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文