Skip to content Skip to sidebar Skip to footer

How To Get Label For Corresponding Swipe In Barchart Of Mpandroidchart?

How to get label for corresponding bar when I swipe the barchart? I have another textview outside of barchart. When I swipe mpandroidchart graph, I need to get x axis label of corr

Solution 1:

In case of OnChartValueSelectedListener, you can do

barChart.setOnChartValueSelectedListener(newOnChartValueSelectedListener() {
        @OverridepublicvoidonValueSelected(Entry e, int dataSetIndex, Highlight h) {
            String value = barChart.getBarData().getXVals().get(e.getXIndex());
        }

        @OverridepublicvoidonNothingSelected() {

        }
    });

In the similar way you can achieve this for other listeners too.

Solution 2:

Implement mChart.setOnChartGestureListener method, and you will see onChartTranslateOverride method.

mChart.getXValue(mChart.getHighestVisibleXIndex());

This will return you the value of the highest visible index after swipe. Hope this answer will help you to solve your problem.

Post a Comment for "How To Get Label For Corresponding Swipe In Barchart Of Mpandroidchart?"