Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected bar x-axis value using MPAndroidChart?

I am using the MPAndroidChart library in my Android graphs app and I need to display the dialog with a title containing the selected bar's x-axis values.

I referred to this wiki entry for click events to the bars in the bar graph. But now I need to get the selected bar x-axis value as a title. Can any one tell me how to achieve it?

like image 210
lakshman Avatar asked Dec 14 '22 09:12

lakshman


1 Answers

Use the OnChartValueSelectedListener:

@Override
public void onValueSelected(Entry e, Highlight h) {

   final String x = chart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), chart.getXAxis());
}

The Highlight object contains additional information regarding the selected position, such as the dataSetIndex, x- and y-position of the selected value in pixels, the selected stack value (in stacked bar chart), ...

Also hava a look at the documentation of highlighting values.

like image 113
Philipp Jahoda Avatar answered Mar 03 '23 14:03

Philipp Jahoda