onChartValueSelectedListener not working in BarChart
I am using MPandroidchart to display Bar chart. On click of a bar , i want to capture the datapoint (Entry) associated with bar . Following is the code snippet : In the code snippet below onChartValueSelectedListener is attached. But when ever I click the bar , it callback never comes to onValueSelected. Seems like a bug with Barchart
BarChart barChart = view.findViewById(R.id.taskProgressGraphView); barChart.setData(data); barChart.setTouchEnabled(true); barChart.setHighlightFullBarEnabled(true); barChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @Override public void onValueSelected(Entry e, Highlight h) { Log.i("Chart ", e.toString());
}
@Override
public void onNothingSelected() {
Log.i("Chart ", "onNothingSelected");
}
});
}
I'm facing the same issue, however I noticed that if I tap on top of the bar (outside of it, which of course shouldn't be case) the onValueSelected gets called :/
I recently realized the bar charts aren't showing up the values when I clicked on it, must be happening after updating the charts version to 3.1.0. Any fixes on this?
When I click and Log the methods it does the thing, but how ever I have a layout that I need to be shown when click and its not showing
It will not work if isHighlightEnabled = false. By default, it works with true.
You have to call barChart.setOnChartValueSelectedListener(this); after implementing OnChartValueSelectedListener.
You will get something like this on click:
Entry, x: 0.55 y: 5.0======Highlight, x: 0.55, y: 5.0, dataSetIndex: 1, stackIndex (only stacked barentry): -1