Reputation: 1034
I have been using the MPAndroidChart library to display a line graph of the currently playing audio in an app I am building. However I want to make it so the user can scroll the chart, and the playback position of the playing audio changes in proportion to the chart scroll.
However I cant seem to find a way to get the closest x-index position to the center of the graph
As you can see in the screenshot, i want to be able to get the x-index behind the red line as the user scrolls, but i cant seem to figure out how to do this.
Any help would be much appreciated.
Thanks Corey B :)
Upvotes: 7
Views: 2916
Reputation: 1448
You can set onChartGestureListener
or onTouchListener
for chart
to catch scroll events and than calculate current plot position:
float lowX = chart.getLowestVisibleX()
float xrange = chart.getVisibleXRange() //better to fix x-ranges, getVisibleXRange may be inaccurate
float centerX = lowX + xrange / 2
Upvotes: 2