---
title: "Touch"
framework: javascript
version: "14.1.0"
---

# Touch

AG Charts implements touch and multi-touch support, enabling interactivity across all devices.

## Touch Options

All interactivity is available via touch input.

For example:

- Tap the series area to show [tooltips](https://www.ag-grid.com/charts/javascript/tooltips/) and [crosshairs](https://www.ag-grid.com/charts/javascript/axes-crosshairs/).
- Tap or double-tap to [toggle a legend item](https://www.ag-grid.com/charts/javascript/legend/#series-visibility-toggling), [reset zoom](https://www.ag-grid.com/charts/javascript/zoom/#double-click-to-reset), or press any of the UI buttons.
- Any click and double-click [events](https://www.ag-grid.com/charts/javascript/events/) are also triggered by a tap or double-tap.
- Long tap to bring up the [context menu](https://www.ag-grid.com/charts/javascript/context-menu/).
- Drag to [zoom the axes](https://www.ag-grid.com/charts/javascript/zoom/#axis-zoom-controls), [pan a zoomed chart](https://www.ag-grid.com/charts/javascript/zoom/#panning), or interact with [annotations](https://www.ag-grid.com/charts/javascript/annotations/).
- Use [two finger pinch gestures](https://www.ag-grid.com/charts/javascript/zoom/#two-finger-zoom-pan) to zoom in or out of a chart, and two finger drag to pan a zoomed chart.

## Single Finger Touch Dragging

By default, Single Finger Touch Drag events are handled like mouse drag events. To change the input handling behaviour of these events, use `touch.dragAction`.

#### Single Finger Touch Dragging

```ts
import {
  AgCartesianChartOptions,
  AgCharts,
  AgTouchOptions,
  AnimationModule,
  CandlestickSeriesModule,
  ContextMenuModule,
  CrosshairModule,
  LegendModule,
  ModuleRegistry,
  NumberAxisModule,
  OrdinalTimeAxisModule,
  ZoomModule,
} from "ag-charts-enterprise";
import { getData } from "./data";

ModuleRegistry.registerModules([
  AnimationModule,
  CandlestickSeriesModule,
  CrosshairModule,
  LegendModule,
  NumberAxisModule,
  OrdinalTimeAxisModule,
  ZoomModule,
  ContextMenuModule,
]);

const options: AgCartesianChartOptions = {
  data: getData(1e3),
  animation: { enabled: false },
  touch: { dragAction: "none" },
  zoom: {
    enabled: true,
    enableAxisDragging: false,
  },
  initialState: {
    zoom: {
      ratioX: { start: 0.48, end: 0.52 },
      ratioY: { start: 0.15, end: 0.6 },
    },
  },
  series: [
    {
      type: "candlestick",
      xKey: "timestamp",
      lowKey: "low",
      highKey: "high",
      openKey: "open",
      closeKey: "close",
    },
  ],
};

options.container = document.getElementById("myChart");

const chart = AgCharts.create(options);

function changeAction(newAction: NonNullable<AgTouchOptions["dragAction"]>) {
  if (options.touch) {
    options.touch.dragAction = newAction;
  }

  chart.update(options);
}

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).changeAction = changeAction;
}
```

[Live example: Single Finger Touch Dragging](https://www.ag-grid.com/charts/typescript/touch/examples/single-finger-touch-dragging)

```js
{
    touch: {
        dragAction: 'drag' | 'hover' | 'none',
    },
}
```

In this example:

- `dragAction: 'none'` disables the chart's Single Finger input handling, scrolling the entire page.
- `dragAction: 'drag'` emulates mouse dragging, panning the viewport if possible.
- `dragAction: 'hover'` emulates mouse movements, updating the tooltip and highlighted node.

## Two Finger Zoom-Pan

By default, charts use two finger gestures to zoom and pan. To pass this gesture to the underlying page, set `enableTwoFingerZoom: false`.

#### Two Finger Zoom-Pan

```ts
import {
  AgCartesianChartOptions,
  AgCharts,
  AnimationModule,
  ContextMenuModule,
  CrosshairModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
  ZoomModule,
} from "ag-charts-enterprise";
import { getData } from "./data";

ModuleRegistry.registerModules([
  AnimationModule,
  CrosshairModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
  ZoomModule,
  ContextMenuModule,
]);

const options: AgCartesianChartOptions = {
  animation: { enabled: false },
  touch: {
    dragAction: "none",
  },
  zoom: {
    enableDoubleClickToReset: false,
    enableTwoFingerZoom: true,
  },
  initialState: {
    zoom: {
      ratioX: { start: 0.48, end: 0.52 },
      ratioY: { start: 0.21, end: 0.82 },
    },
  },
  tooltip: {
    enabled: false,
  },
  axes: {
    y: {
      type: "number",
      interval: {
        minSpacing: 80,
        maxSpacing: 120,
      },
    },
    x: {
      type: "number",
      nice: false,
      interval: {
        minSpacing: 80,
        maxSpacing: 120,
      },
      label: {
        autoRotate: false,
      },
    },
  },
  data: getData(),
  series: [
    {
      type: "line",
      xKey: "year",
      yKey: "spending",
    },
  ],
};

options.container = document.getElementById("myChart");

const chart = AgCharts.create(options);

function setEnabled(enabled: boolean) {
  if (options.zoom) {
    options.zoom.enableTwoFingerZoom = enabled;
  }

  chart.update(options);
}

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).setEnabled = setEnabled;
}
```

[Live example: Two Finger Zoom-Pan](https://www.ag-grid.com/charts/typescript/touch/examples/two-finger-zoompan)

```js
{
    zoom: {
        enableTwoFingerZoom: true | false,
    },
}
```

## Long Tap

Long Tapping the chart will open the [Context Menu](https://www.ag-grid.com/charts/javascript/context-menu/), if available.

#### Long Tap

```ts
import {
  AgCartesianChartOptions,
  AgCharts,
  AnimationModule,
  CategoryAxisModule,
  ContextMenuModule,
  CrosshairModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
} from "ag-charts-enterprise";

ModuleRegistry.registerModules([
  AnimationModule,
  CategoryAxisModule,
  CrosshairModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
  ContextMenuModule,
]);

const options: AgCartesianChartOptions = {
  title: {
    text: "Financial Performance Overview",
  },
  animation: { enabled: false },
  data: [
    {
      year: 2018,
      revenue: 120,
      expenses: 80,
      profit: 40,
      investments: 30,
      taxes: 20,
      dividends: 10,
      rAndD: 25,
    },
    {
      year: 2019,
      revenue: 140,
      expenses: 90,
      profit: 50,
      investments: 40,
      taxes: 25,
      dividends: 12,
      rAndD: 30,
    },
    {
      year: 2020,
      revenue: 160,
      expenses: 100,
      profit: 60,
      investments: 50,
      taxes: 30,
      dividends: 15,
      rAndD: 35,
    },
    {
      year: 2021,
      revenue: 180,
      expenses: 110,
      profit: 70,
      investments: 55,
      taxes: 35,
      dividends: 18,
      rAndD: 40,
    },
    {
      year: 2022,
      revenue: 200,
      expenses: 120,
      profit: 80,
      investments: 60,
      taxes: 40,
      dividends: 20,
      rAndD: 45,
    },
  ],
  series: [
    { type: "line", xKey: "year", yKey: "revenue", yName: "Revenue" },
    { type: "line", xKey: "year", yKey: "expenses", yName: "Expenses" },
    { type: "line", xKey: "year", yKey: "profit", yName: "Profit" },
    { type: "line", xKey: "year", yKey: "investments", yName: "Investments" },
    { type: "line", xKey: "year", yKey: "taxes", yName: "Taxes" },
    { type: "line", xKey: "year", yKey: "dividends", yName: "Dividends" },
    { type: "line", xKey: "year", yKey: "rAndD", yName: "R&D Spending" },
  ],
};

options.container = document.getElementById("myChart");

const chart = AgCharts.create(options);
```

[Live example: Long Tap](https://www.ag-grid.com/charts/typescript/touch/examples/long-tap)

## API Reference

#### Touch

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| dragAction | 'none' \| 'drag' \| 'hover' | 'drag' | Sets the input handling behaviour for single-finger touch drag events.  - `'none'` - ignores these events, typically causing the default page-scrolling behaviour. - `'hover'` - makes these behave like mouse hover events, showing tooltip and crosshairs. - `'drag'` - makes these behave like mouse drag events (moving while holding left-button). |
