I want to set a vertical line in center of LineChart
like this:
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:
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?
Take a look at the method
in the BarLineChartBase class (parent for a LineChart). In that method you have all data to draw your line right in the middle. Something like this
Maybe it's too late but here is my answer. It's encoded in Swift using Charts (MPAndroidCharts port for iOS) but API is 99% the same ;)
This will display a vercital line over the point defined by your xValue variable.
Hope it helps!
Have you tried using
getEntryByTouchPoint
on your chart supplying the x and y coordinates of the center of the chart?