与图表交互
这个库允许你完全自定义与图表视图触摸交互的各种情况以及对交互其作用的回调方法。
打开/关闭交互
- setTouchEnabled(boolean enabled): 允许你打开或者关闭与图表的所有触摸交互的情况。
- setDragEnabled(boolean enabled): 打开或关闭对图表的拖动。
- setScaleEnabled(boolean enabled):打开或关闭对图表所有轴的的缩放。
- setScaleXEnabled(boolean enabled): 打开或关闭x轴的缩放
- setScaleYEnabled(boolean enabled): 打开或关闭y轴的缩放。
- setPinchZoom(boolean enabled): 如果设置为true,挤压缩放被打开。如果设置为false,x和y轴可以被单独挤压缩放。
- setHighlightEnabled(boolean enabled): 如果设置为true,在图表中通过触屏高亮或选择值是可能的。
- setHighlightPerDragEnabled(boolean enabled): 设置为true时允许高亮显示拖动结束的对象在缩放到最下时。默认:true
- setHighlightIndicatorEnabled(boolean enabled): 如果设置为true, 指标线(或杆)将展示被选择的线的绘制的值。
通过编程自动高亮
- highlightValues(Highlight[] highs): 突出显示给定索引处的值在被给定的数据集中。提供null或空的数组将取消所有的高亮。
- highlightValues(Highlight[] highs): 突出显示给定xIndex为索引在被给定的数据集中。提供-1时将去取消所有的高亮
- getHighlighted():返回一个Highlight[]的数组包含关于所有高亮入口的信息,它们的x-索引和数据集的索引。
编程自动高亮将不产生OnChartValueSelectedListener回调
选择回调
这个库提供了大量的监听回调在交互后。其中一个是OnChartValueSelectedListener,在触屏高亮值的时候进行回调。
1. public interface OnChartValueSelectedListener {
2. /**
3. * Called when a value has been selected inside the chart.
4. *
5. * @param e The selected Entry.
6. * @param dataSetIndex The index in the datasets array of the data object
7. * the Entrys DataSet is in.
8. * @param h the corresponding highlight object that contains information
9. * about the highlighted position
10. */
11. public void onValueSelected(Entry e, int dataSetIndex, Highlight h);
12. /**
13. * Called when nothing has been selected or an "un-select" has been made.
14. */
15. public void onNothingSelected();
16. }
让你的类接收回调实现这个接口并设置它作为图表的一个listener
1. chart.setOnChartValueSelectedListener(this);
手势回调
OnChartGestureListener将允许你对图表上的手势作出反应:
1. public interface OnChartGestureListener {
3. /**
4. * Callbacks when the chart is longpressed.
5. *
6. * @param me
7. */
8. public void onChartLongPressed(MotionEvent me);
10. /**
11. * Callbacks when the chart is double-tapped.
12. *
13. * @param me
14. */
15. public void onChartDoubleTapped(MotionEvent me);
17. /**
18. * Callbacks when the chart is single-tapped.
19. *
20. * @param me
21. */
22. public void onChartSingleTapped(MotionEvent me);
24. /**
25. * Callbacks then a fling gesture is made on the chart.
26. *
27. * @param me1
28. * @param me2
29. * @param velocityX
30. * @param velocityY
31. */
32. public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY);
33. }
让你的类接收回调实现这个接口并设置它作为图表的一个listener
1. chart.setOnChartGestureListener(this);
