MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Chart conflict with ScrollView.

Open 127001david opened this issue 8 years ago • 5 comments

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! : )

127001david avatar Aug 31 '16 07:08 127001david

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).

127001david avatar Sep 21 '16 08:09 127001david

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;
        }
    });

maheshhchandra avatar Mar 05 '19 15:03 maheshhchandra

thanks

127001david avatar Mar 25 '19 06:03 127001david

Thank you, this helped me as well :)

danielle-h avatar Nov 17 '21 10:11 danielle-h

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...

LijuDaniel avatar Dec 16 '22 02:12 LijuDaniel