user5974345
user5974345

Reputation:

How to get the label value of the clicked bar on HorizontalBarChart in MPAndroidChart?

I am using HorizontalBarChart by com.github.PhilJay:MPAndroidChart:v2.2.5. I want to get the string values of the bar(label value) which I clicked.

This is my yAxis. I have 7 bars.

chart = (HorizontalBarChart) vLayout.findViewById(R.id.hchart);

final ArrayList<String> xAxis = new ArrayList<>();
        xAxis.add("FG0028");
        xAxis.add("FG0010");
        xAxis.add("FG0009");
        xAxis.add("FG0005");
        xAxis.add("FG0004");
        xAxis.add("FG0002");
        xAxis.add("FG0001");

I want to get the label value of the bar i click, for example FG0028

Upvotes: 2

Views: 1713

Answers (1)

Nikita Shah
Nikita Shah

Reputation: 156

Have you try to implement OnChartValueSelectedListener present in the mpandroidchart library

@Override
public void onNothingSelected() {
    Log.d("Nothing selected", "Nothing selected.");
}

@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
   Log.d("Entry selected", e.toString());
     Log.d("", "low: " + mChart.getLowestVisibleXIndex() + ", high: "    + mChart.getHighestVisibleXIndex());
  }

Upvotes: 2

Related Questions