2016-11-23 49 views

回答

2

有一個接口OnChartGestureListener,其中包含了兩個方便的方法:

void onChartDoubleTapped(MotionEvent me)

void onChartSingleTapped(MotionEvent me)

他們的名字爲自己說話。剛上Chart調用適當的方法:

public void setOnChartGestureListener(OnChartGestureListener l)

例子:

mChart.setOnChartGestureListener(new OnChartGestureListener() { 
    @Override 
    public void onChartDoubleTapped(MotionEvent me) { 
     Toast.makeText(MainActivity.this, "Double", Toast.LENGTH_SHORT).show(); 
    } 

    @Override 
    public void onChartSingleTapped(MotionEvent me) { 
     Toast.makeText(MainActivity.this, "Single", Toast.LENGTH_SHORT).show(); 
    } 
    }); 

爲參數你MotionEvent

要獲得X和Y值,請撥打:

mChart.getHighlightByTouchPoint(me.getX(), me.getY()).getX(); 
mChart.getHighlightByTouchPoint(me.getX(), me.getY()).getY() 

它應該BarChart工作。還記得禁用變焦上雙擊:

mChart.setDoubleTapToZoomEnabled(false); 

然而,它可能無法正常工作,因爲我已經看到了PieChart這是行不通的。只有長按和單按才能使用它。