MPAndroidChart:如何在点击时在所有行上显示圆圈?

时间:2018-11-11 17:57:58

标签: android mpandroidchart

我在图表中显示了几个LineDataSet。默认情况下,我不需要显示圈子。但是,当用户单击图表时,我需要根据x值在所有线上显示圆圈。如何实现?

enter image description here

1 个答案:

答案 0 :(得分:1)

首先,您需要对数据集设置虚假绘制圆,如下所示:

lineDataSet.setDrawCircles(false);

之后,您需要按以下方式实现OnChartGestureListener():

    lineChart.setOnChartGestureListener(new OnChartGestureListener()
    {
        @Override
        public void onChartTranslate(MotionEvent me, float dX, float dY) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onChartSingleTapped(MotionEvent me)
        {
            // TODO Auto-generated method stub
            if(lineDataSet.isDrawCirclesEnabled())
            {
                lineDataSet.setDrawCircles(false);
            }
            else
            {
                lineDataSet.setDrawCircles(true);
            }
        }

        @Override
        public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {

        }

        @Override
        public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {

        }

        @Override
        public void onChartLongPressed(MotionEvent me) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onChartFling(MotionEvent me1, MotionEvent me2,
                                 float velocityX, float velocityY) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onChartDoubleTapped(MotionEvent me) {
            // TODO Auto-generated method stub

        }
    });

这将完成工作。祝你好运兄弟!