该库允许您完全自定义与图表视图的触摸(和手势)交互,并通过回调方法对交互作出反应。
启用/禁用互动
- 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,图表在触摸后继续滚动。默认值:true。
- setDragDecelerationFrictionCoef(float coef):减速摩擦系数在[0; 1]间隔,较高的值表示速度将缓慢降低,例如,如果设置为0,它将立即停止。1是无效值,将自动转换为0.9999。
突出显示值
突出显示部分将介绍如何通过点按手势和编程方式突出显示条目。
手势回调
OnChartGestureListener将允许您对图表上的手势做出反应:
public interface OnChartGestureListener {
/**
*当触摸手势在图表上开始时的回调(ACTION_DOWN)
*
* @param me
* @param lastPerformedGesture
*/
void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
/**
* 当触摸手势在图表上结束时的回调(ACTION_UP, ACTION_CANCEL)
*
* @param me
* @param lastPerformedGesture
*/
void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
/**
* 当图表被长按时回调。
*
* @param me
*/
public void onChartLongPressed(MotionEvent me);
/**
*图表双击时回调。
*
* @param me
*/
public void onChartDoubleTapped(MotionEvent me);
/**
*当图表单点击时回调。
*
* @param me
*/
public void onChartSingleTapped(MotionEvent me);
/**
* 在图表上做出一个简单的滑动时回调。
*
* @param me1
* @param me2
* @param velocityX
* @param velocityY
*/
public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY);
/**
*当图表通过缩放手势缩放/缩放时回调。
*
* @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);
/**
*当图表通过拖动手势移动/翻转时回调。
*
* @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);