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

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

启用/禁用交互
  • setTouchEnabled(boolean enabled):可以启用/禁用所有与图表的触摸交互。
  • setDragEnabled(boolean enabled):启用/禁用拖动(平移)图表。
  • setScaleEnabled(boolean enabled):启用/禁用图表两个轴的缩放。
  • setScaleXEnabled(boolean enabled):启用/禁用x轴的缩放。
  • setScaleYEnabled(boolean enabled):启用/禁用y轴的缩放。
  • setPinchZoom(boolean enabled):如果设置为true,捏拉缩放启用。如果禁用,x和y轴可以单独缩放。
  • setDoubleTapToZoomEnabled(boolean enabled):设置为false,不允许使用双击屏幕来放大图表。
图标的加速/减速
  • setDragDecelerationEnabled(boolean enabled):如果设置为true,触摸抬起后,图表继续滚动。默认值:真的。
  • setDragDecelerationFrictionCoef(float coef):减速摩擦系数在[0,1]区间,值越大表示速度减少越慢,例如如果设置为0,它将立即停止。1是一个无效的值,并将自动转换为0.9999。
高亮显示

如何通过点击手势和编程方式让允许条目高亮显示,在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);

你可能感兴趣的:(MPAndroidChart中文翻译(二与图表交互))