Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart set center vertical line

I want to set a vertical line in center of LineChart like this:

enter image description here

When scrolling to each point, it can notify to change the date below (the orange date field). And it can move left or right programmatically by click on arrow button.

Currently, I can set viewport and allow moving to center with this code:

LineData data = new LineData(xVals, dataSets);
mChart.setScaleMinima((float) data.getXValCount() / 7f, 1f);
mChart.moveViewTo(0, 7, YAxis.AxisDependency.LEFT);

And get the result:

enter image description here

How can I draw and set a vertical line like above?

Update:

For the listener, I think OnChartGestureListener onChartTranslate(MotionEvent me, float dX, float dY) may help. What I need is the distance between 2 points and how to calculate how many points are in current view port. Does anyone know that?

like image 476
ductran Avatar asked Nov 19 '15 12:11

ductran


1 Answers

Have you tried using getEntryByTouchPoint on your chart supplying the x and y coordinates of the center of the chart?

public Entry getEntryByTouchPoint(float x, float y)

returns the Entry object displayed at the touched position of the chart

like image 199
Cory Charlton Avatar answered Sep 27 '22 23:09

Cory Charlton