MPAndroidChartAndroid知识Android开发

MPAndroidChart中文翻译(二与图表交互)

2016-10-11  本文已影响180人  鹿小纯0831

这个库允许你定制与图表视图之间触摸操作(手势),并通过回调方法来进行相应。

启用/禁用交互
图标的加速/减速
高亮显示

如何通过点击手势和编程方式让允许条目高亮显示,在highlightning section有详细介绍。

手势回调

实现OnChartGestureListener这个接口里的方法来对图表手势进行响应:

public interface OnChartGestureListener { 
     /** 
      * Callbacks when a touch-gesture has started on the chart (ACTION_DOWN) 
      * @param me 
      * @param lastPerformedGesture 
      */ 
     void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture); 
     /**  
      * Callbacks when a touch-gesture has ended on the chart (ACTION_UP, ACTION_CANCEL) 
      * @param me 
      * @param lastPerformedGesture 
      */ 
     void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture); 
     /** 
      * Callbacks when the chart is longpressed. 
      * @param me 
      */ 
     public void onChartLongPressed(MotionEvent me);
     /** 
      * Callbacks when the chart is double-tapped. *
      * @param me 
      */ 
     public void onChartDoubleTapped(MotionEvent me); 
     /** 
      * Callbacks when the chart is single-tapped. 
      * @param me 
      */ 
     public void onChartSingleTapped(MotionEvent me); 
     /** 
      * Callbacks then a fling gesture is made on the chart. 
      * @param me1 
      * @param me2
      * @param velocityX 
      * @param velocityY 
      */ 
     public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY); 
     /**
      * Callbacks when the chart is scaled / zoomed via pinch zoom gesture.            
      * @param me
      * @param scaleX scalefactor on the x-axis 
      * @param scaleY scalefactor on the y-axis 
      */
     public void onChartScale(MotionEvent me, float scaleX, float scaleY);      
     /**          
      * Callbacks when the chart is moved / translated via drag gesture. 
      * @param me 
      * @param dX translation distance on the x-axis
      * @param dY translation distance on the y-axis 
      */
     public void onChartTranslate(MotionEvent me, float dX, float dY);
}

接下来就很简单了,让你的类实现这个接口和她的回调方法:

chart.setOnChartGestureListener(this);
上一篇下一篇

猜你喜欢

热点阅读