0
votes

I am using MPAndroidChart in order to create a grouped bars chart. Everything is fine but I am not able to display a MarkerView properly.

I'd like to show some information in the MarkerView depending on entry index, but I just can retrieve x or y values.

refreshContent method

@Override
public void refreshContent(Entry e, Highlight highlight) {
        Log.d("MARKER", "x:" + e.getX() + " | y:" + e.getY() 
                + " | hx:" + highlight.getX() + " | hy:" + highlight.getY() 
                + " | dataindex:" + highlight.getDataIndex()
                + " | datasetindex:" + highlight.getDataSetIndex());
        super.refreshContent(e, highlight);
}

This is my log output:

x:2.7349997 | y:65.0 | hx:2.7349997 | hy:65.0 | dataindex:1 | datasetindex:1

Dataindex is always 1 no matter which bar I tap. Datasetindex shows correct value depending on index within group bar.

I realized I can use getData() method from Entry, so I used another constructor for each BarEntry:

new BarEntry(x, y, "extraData");

however, e.getData() is null in refreshContent.

What am I doing wrong?

1

1 Answers

2
votes

The trick was on my chart because is composed by a bar chart and a line chart. So, when I tap a point in my chart I am receiving refreshContent event because of a tap in my line chart. Then, if I set the data object in for each line chart entry, now it is received on refreshContent method. However my solution was to disable highlighting to line data set:

lineDataSet.setHighlightEnabled(false);

This way every tap on chart belongs always to bar chart.