MPAndroidChart
MPAndroidChart copied to clipboard
Chart conflict with ScrollView.
When I use LineChart in a ScrollView(like vertical ) I found when I move a little distance on y-axis direction the move event will be thrown to the ScrollView,When i set touchListener on LineChart it called MotionEvent.ACTION_CANCEL.
I guess if it is the way you solve the scroll conflict problem but I feel the user experience is not very good.I thank the move distance can be custom or much more longer than now will be better.I think if it can be solve in GestureDetector but failed, it will be nice if you can help me,thanks! : )
I solve it like this:
chart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
scrollView.requestDisallowInterceptTouchEvent(true);
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP: {
scrollView.requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
just add a TouchListener on chart and call the external ScrollView's requestDisallowInterceptTouchEvent(boolean).
Added option to let scrollview listen if chart has been scrolled to start or end of xAxis
chart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(!(chart.getLowestVisibleX() == chart.getXAxis().getAxisMinimum() || chart.getHighestVisibleX() == chart.getXAxis().getAxisMaximum())){
switch (event.getAction()) {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP: {
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
case MotionEvent.ACTION_DOWN: {
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
case MotionEvent.ACTION_MOVE:{
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
}
}
return false;
}
});
thanks
Thank you, this helped me as well :)
Hi Guys, No need to use external scroll views
Comment computeScroll() method in the bellow path. This method may block your thread for 2, 3 minutes and this leads to delay, lagging, live value update issues , etc..
com/github/mikephil/charting/listener/BarLineChartTouchListener.java
Definitely this will resolve all scrolling issues like delay, hangs etc...