Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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??

like image 613
User Code Avatar asked Jun 09 '15 12:06

User Code


1 Answers

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
}
like image 133
Philipp Jahoda Avatar answered Oct 21 '22 21:10

Philipp Jahoda