MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

onChartValueSelectedListener not working in BarChart

Open smukkawa opened this issue 5 years ago • 5 comments

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");
        }
    });

}

smukkawa avatar Jan 28 '19 06:01 smukkawa

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 :/

federicomiralles avatar Sep 25 '19 13:09 federicomiralles

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?

amrit018 avatar Nov 11 '19 19:11 amrit018

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

fabrizzioalco avatar Jan 28 '20 04:01 fabrizzioalco

It will not work if isHighlightEnabled = false. By default, it works with true.

DaisukeNagata avatar Jun 01 '20 13:06 DaisukeNagata

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

ArmanAndr avatar Sep 22 '20 18:09 ArmanAndr