Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart click on pieChart Slices

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?

like image 906
mbagher Avatar asked Jul 22 '15 10:07

mbagher


1 Answers

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 :) !
    }
}
like image 63
marco Avatar answered Sep 18 '22 11:09

marco