How to control click on each slice in a pie chart of MPAndroidChart? I know that we can control click on pie chart, but I want clicking on slice of chart and find which slice is clicked?
Your activity must implement the OnChartValueSelectedListener interface.
As written in the documentation "let your class that should receive the callbacks implement this interface and set it as a listener to the chart"
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 :) !
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With