Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a label when a value is selected [MPAndroidChart]

I want to show a label with specific data when a value is selected like in the demo-Image of what I want:

Image of the I want

so I paste this code (found in the source of the exemple):

protected RectF mOnValueSelectedRectF = new RectF();

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

    if (e == null)
        return;

    RectF bounds = mOnValueSelectedRectF;
    mChart.getBarBounds((BarEntry) e, bounds);
    MPPointF position = mChart.getPosition(e, AxisDependency.LEFT);

    Log.i("bounds", bounds.toString());
    Log.i("position", position.toString());

    Log.i("x-index",
            "low: " + mChart.getLowestVisibleX() + ", high: "
                    + mChart.getHighestVisibleX());

    MPPointF.recycleInstance(position);
}

but it doesn't work, the log are displayed but nothing happen on the screen. What I have forget or miss

like image 659
Firerazzer Avatar asked Oct 21 '25 03:10

Firerazzer


2 Answers

To display a marker with something inside when a value is selected we have to use a MarkerView and not the valueSelected listener.

All the necessary doc for create yours is here : https://github.com/PhilJay/MPAndroidChart/wiki/IMarker-Interface

like image 149
Firerazzer Avatar answered Oct 26 '25 17:10

Firerazzer


Have you written below the line in your code?

mChart.setOnChartValueSelectedListener(this);
like image 20
Mehul Kabaria Avatar answered Oct 26 '25 18:10

Mehul Kabaria