Reputation: 2204
How to listen to the scroll finish event in mpandroidchart.
I overrided the OnChartGestureListener
and OnChartValueSelectedListener
but it does not seems to work. onChartTranslate()
method gets callback even after the scroll gets end.
onChartGestureStart()
gets called when the user touches the chart and onChartGestureEnd()
gets called once the user stops touching the chart.
So, i need to catch the event which gets called when the scroll gets finished.
So, Can you give a headsup on how to listen to the scroll end of linechart in mpandroidchart.
Upvotes: 11
Views: 3144
Reputation: 51
I struggled with the same problem a lot. After i could not find solution, what i did is to set
chart.setDragDecelerationEnabled(false);
Thus there is no continuation of scrolling after touch up and i could get the last X coordinates with
chart.setOnChartGestureListener(new OnChartGestureListener() {
@Override
public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
}
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
float lastX = holder.chart.getLowestVisibleX();
saved_x.set(position, lowX);
}
});
Upvotes: 1
Reputation: 1439
the more better way is to use library's own listener with this logic like:
override fun onChartTranslate(me: MotionEvent?, dX: Float, dY: Float) {
if(dX > 0){
//backward dragging
}
else if(mChart.highestVisibleX == mChart.xAxis.axisMaximum){
//forward dragging reached at max (can not be dragged more)
}
}
Upvotes: 1
Reputation: 31
this worked for me checked both the start and end of scroll in chart
chart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(!(chart.getLowestVisibleX() == chart.getXAxis().getAxisMinimum() || chart.getHighestVisibleX() == chart.getXAxis().getAxisMaximum())){
// Do your work here
Toast.makeText(getContext(),"Hello Scroll to end check working",Toast.LENGTH_LONG).show();
return false;
}
});
Upvotes: 2
Reputation: 3189
You need to do something as follows:
@Override
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture)
{
if(data.getEntryCount() == (int) chart.getHighestVisibleX())
{
// Do your work here
Toast.makeText(getContext(),"Hello Scroll to end check working",Toast.LENGTH_LONG).show();
}
}
This will check if your scroll has reached for last value on x-Axis. You may need little bit customization in that but this is the way to do so.
Upvotes: 1