Menu

Handle pan support

This section provides information on handling scroll left and right actions inside the graph view. Perform the following steps to add pan API support for a graph view.

Automatic Pan Limit

This feature automatically prevents the series disappearing to the left, right, up, and down, while the pan uses the range set by the user.

1. Set the X and Y axis 'min' and 'max' values correctly through the renderer instance, else automatic panning calculation could not be done correctly. When adding the X and Y values, one of the value should be equal or above [(min + max)/2] for both X-axis and Y-axis.

In the following example, initial ranges of panMinimumX is -1, panMaximumX is 6, panMinimumY is 10, and panMaximumX is 150.

<rendererInstance>.setXAxisMin(-1, 0)
<rendererInstance>.setXAxisMax(6, 0)
<rendererInstance>.setYAxisMax(150, 0)
<rendererInstance>.setYAxisMin(-10, 0)

2. Create a graphical view and add the pan left listener to the view.

private OnClickListener PanLeftListener = new OnClickListener() {
 @Override
 public void onClick(View v) {
  if (v != null)
   v.panBy(50);
 }
};

3. Add the pan right listener to the graph view.

private OnClickListener PanRightListener = new OnClickListener() {
 @Override
 public void onClick(View v) {
  if (candleChartView != null)
   candleChartView.panBy(-50);
 }
};

Manual Pan Limit

This feature allows the user to set the left, right, up, and down limit. When going for manual pan limit, disappearing of the series is possible.

1. Disable the automatic pan flag using the XYMultipleSeriesRenderer instance.

<rendererInstance>. setAutomaticLimiting(false)

2. Set the pan limits using the XYMultipleSeriesRenderer instance. The values are panMinimumX, panMaximumX, panMinimumY, and panMaximumY.

<rendererInstance>. setPanLimits(new double[]{ -2, 100, -20, 200 })

3. Create a graphical view and add the pan left listener to the view.

private OnClickListener PanLeftListener = new OnClickListener() {
 @Override
 public void onClick(View v) {
  if (v != null)
   v.panBy(50);
 }
};

4. Add the pan right listener to the graph view.

private OnClickListener PanRightListener = new OnClickListener() {
 @Override
 public void onClick(View v) {
  if (candleChartView != null)
   candleChartView.panBy(-50);
 }
};