Interaction

Pan, zoom, scale and keyboard controls, plus the events and hooks to build your own interactions.

Charts are interactive out of the box, with familiar gestures on mouse, trackpad and touch.

Gestures

WhereGestureEffect
PlotDragPan in time; vertically too once the price scale was adjusted
PlotWheel / trackpad scrollZoom around the pointer; horizontal scroll pans
PlotPinch (trackpad or touch)Zoom
Plot (touch)SwipePan with kinetic scrolling
Price axisDrag / wheelScale that price scale (turns its autoscale off)
Price axisDouble-clickAutoscale again
Time axisDragZoom horizontally
Time axisDouble-clickReset the view
Pane separatorDrag / double-clickResize panes / maximize (and restore) the pane below

Keyboard

The chart container is focusable (tabIndex={0}). When it has focus:

KeyAction
← / →Pan one bar (Shift: ten bars)
↑ / + / =Zoom in
↓ / -Zoom out
HomeJump to the first bar
EndJump to the latest bar

Your keydown listeners run first and can call preventDefault() to replace a default.

Options

PropEffect
pan={false} / zoom={false}Disable panning / zooming.
interactive={false}Disable every pointer and keyboard interaction (the chart still renders).
zoomAnchor"mouse" (default), "right", "lastVisible" or a function.
zoomMultiplierZoom factor per wheel step (default 1.1).
kineticScrollMomentum after touch swipes (default true).
clampKeep the data on screen: true, "left", "right", "both" or a function.
minBarSpacing / maxBarSpacingZoom limits in pixels per bar.
<Pane yPan={false}>Keep plot drags horizontal even after the price scale was adjusted.

Callbacks

<ChartCanvas
  data={bars}
  onVisibleRangeChange={({ from, to, start, end }) => {}}
  onCrosshairMove={(crosshair) => {}} // null when the pointer leaves
  onReachStart={(firstX) => {}} // load older data
  onReachEnd={(lastX) => {}}
/>

Events & hooks

Inside the chart, useChartEvent subscribes to pointer events translated into chart coordinates: plot-relative x / y, the pane, the nearest data index, the time under the pointer and price(scaleId?). Event types are pointerdown, pointermove, pointerup, pointerleave, drag, dragend, click, dblclick, contextmenu, plus keydown, rangechange, crosshair and datachange.

function ClickToLog() {
  useChartEvent("click", (e) => console.log(e.index, e.price(), e.paneId));
  return null;
}

useChartState(selector) re-renders a component when part of the chart state changes, for example the hovered bar:

const index = useChartState((s) => s.crosshair?.index ?? s.dataLength - 1);

For objects users can hover, click and drag (drawings, draggable price lines), register a hit target with useHitTarget. Hit targets are tested before panning, from the highest zIndex down; onDrag events carry the pointer position as e.price() and e.time.

See the draggable line example →

Syncing charts

Charts with the same syncId share the crosshair; add syncRange to pan and zoom them together.

See the synced charts example →

On this page