2

I'm using GraphView for Android, and i'm trying to display the datapoint value above said datapoint in case of an onClick event. Currently, i'm using

series.setOnDataPointTapListener(new OnDataPointTapListener() { @Override public void onTap(Series series, DataPointInterface dataPoint) { Toast.makeText(MainActivity.this, dataPoint.getY(), Toast.LENGTH_SHORT).show(); } });

Is there a way of showing the value right above the datapoint ? Any help would be much appreciated.

Nabila K
  • 21
  • 3

1 Answers1

0

I was able to add text on top of datapoints by using PointsGraphSeries with a custom shape (text):

PointsGraphSeries<DataPoint> seriesPoints = new PointsGraphSeries<>(dataPoints);
seriesPoints.setCustomShape(new PointsGraphSeries.CustomShape() {
    @Override
    public void draw(Canvas canvas, Paint paint, float x, float y, DataPointInterface dataPoint) {
        paint.setColor(Color.BLACK);
        paint.setTextSize(38);
        canvas.drawText(String.valueOf(dataPoint.getY()), x, y, paint);
    }
});
mGraph.addSeries(seriesPoints);

In your case, you could remove the text after some delay with:

mGraph.removeSeries(seriesPoints);
Raphael Petegrosso
  • 3,870
  • 2
  • 24
  • 27
  • Hi @Raphael, Can you share a screenshot? How will it look after that? AND Can this be work on LineGraph? – meekash55 Nov 19 '20 at 14:34