安卓achartengine - 如何识别这条被触摸的条形图?这条、如何识别、条形图、achartengine

2023-09-06 04:00:13 作者:痞唇

荫工作的一个Android应用程序,并使用AChartEngine了吧图表。 一切工作,因为它应该只是我想不通这条图中的被触摸(没有点击)。似乎.getCurrentSeriesAndPoint()没有OnTouchListener内工作。它每次返回NULL。 当我使用OnClickListener一切工作正常,但我需要知道哪条是感动(ACTION_DOWN和Action_Up)没有点击。

Iam working on an android app and using AChartEngine for bar charting. Everything is working as it should except that I can't figure out which bar in the graph is touched (not clicked). It seems that .getCurrentSeriesAndPoint() isn't working within the OnTouchListener. It's everytime returning NULL. When I'm using OnClickListener everything is working fine, but I need to know which bar is touched (Action_Down and Action_Up) not clicked.

时.getCurrentSeriesAndPoint()不工作在总体上TouchListener?有一种解决方法或另一种方式来实现这条被触动?

Is .getCurrentSeriesAndPoint() not working in a TouchListener in general? Is there a workaround or another way to realize which bar is touched?

mChartView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();


            SimpleSeriesRenderer r = new SimpleSeriesRenderer();
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:{
                        Toast.makeText(MainActivity.this, "DOWN", Toast.LENGTH_SHORT) .show();                          
                        if(seriesSelection != null) touchedBar = seriesSelection.getPointIndex();
                        break;}

                case MotionEvent.ACTION_UP:{
                        Toast.makeText(MainActivity.this, "UP", Toast.LENGTH_LONG) .show();                         
                        touchedBar = 0;
                        break;}
                default: break;
            }

            mRenderer.removeAllRenderers(); 
            r.setColor(Color.RED);
            r.setSelectedBar(ClickedBar);
            mRenderer.addSeriesRenderer(r);                 
            mChartView.repaint();

            return true;
        }
    });

亲切的问候 基督教

kind regards Christian

推荐答案

它应该与触摸监听器。但是,你还是要做到这一点:

It should work with the touch listener. However, you still have to do this:

mRenderer.setClickEnabled(true);

AChartEngine使用的onTouchEvent内部,所以有可能是你的触摸事件在ACE一个接着调用,因此这可能是原因没有得到预期的值。

AChartEngine uses the onTouchEvent internally, so it is possible that your touch event is called after the ACE one, so this may be the cause for not getting the expected values.