MPAndroidChart单击pieChart切片
作者:互联网
如何控制MPAndroidChart饼图中的每个切片的单击?我知道我们可以控制单击饼图,但是我想单击图的切片并查找单击了哪个切片?
解决方法:
您的活动必须实现OnChartValueSelectedListener接口.
如documentation中所述,“让您应该接收回调的类实现此接口并将其设置为图表的侦听器”
public class MyActivity implements OnChartValueSelectedListener{
@Override
public void onNothingSelected(){
// do stuff
}
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h){
Log.i("I clicked on", String.valueOf(e.getXIndex()) );
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
...
(PieChart)chart = (PieChart) findViewById(R.id.chart);
...
chart.setOnChartValueSelectedListener(this); // remember this :) !
}
}
标签:mpandroidchart,android 来源: https://codeday.me/bug/20191028/1949601.html