How to get bar click event from horizontalbar charts of MPcharts in android?

3.3k views Asked by At

I am using MPAndroidChart library.

I have used Horizontal bar charts in my dashboard.

I want to navigate to another activity by clicking particular bar of that chart.

How can i do this??

1

There are 1 answers

3
Philipp Jahoda On BEST ANSWER

That's actually pretty easy, all you have to do is use the OnChartValueSelectedListener and start your new Activity from the callback methods.

You can find an example of how that works here.

Basically, implement the listener in your class that holds the chart:

public class SomeClass implements OnChartValueSelectedListener {

Set the listener to the chart:

chart.setOnChartValueSelectedListener(this);

Start your new activity in the callback:

@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
    // start new activity
}