To handle events inside graph view

This section provides information on handling pre-defined gesture events inside a Graph view. The pre-defined events supported in gesture are Double Tap, Down, Fling, Long Press, Scroll, and Single Tap.

Perform the following steps to add a gesture listener for graph view.

1. Create a graphical view and add the gesture listener to this graphical view.

private GestureDetector mGestureDetector;
View v = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer);

2. Define the gesture listener to handle specific actions with respect to a particular event. In the following example, Long Press is handled to display the chart values in the form of toast. Events such as Double Tap, Single Tap, and so on can be handled in the similar way.

mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
 public void onLongPress(MotionEvent e) {
  SeriesSelection seriesSelection =
   ((GraphicalView) lineChartView).getCurrentSeriesAndPoint();
  if (seriesSelection == null) {
   // Do nothing when no series is selected
  } else {
   Toast.makeText(getActivity(), "Series Name : " + mDataset.getSeriesAt(seriesSelection.getSeriesIndex()).getTitle() + '\n' + (int) seriesSelection.getXValue() + " : " + (int) seriesSelection.getValue(), Toast.LENGTH_SHORT).show();