Foundations

Brushing & Zoom

Brushing lets users focus on a specific time range while keeping the full dataset intact. The callback provides the selected domain so you can sync filters elsewhere in the UI.

Example

Drag across the chart to create a selection. The preview logs the brushed domain and exposes a reset control above the chart.

Usage

const [brushDomain, setBrushDomain] = useState<[Date, Date] | null>(null);

<Chart.Root
  data={data}
  height={360}
  brush
  onBrush={setBrushDomain}
>
  <Chart.XAxis
    label="Time"
    domain={brushDomain ?? undefined}
    nice={false}
  />
  {/* series */}
</Chart.Root>

Props

Chart.Root
PropTypeDefaultDescription
brushbooleanfalseEnables the interactive brush overlay that lets users select a time window.
onBrush(domain: [Date, Date] | null) => voidCallback invoked whenever the brush selection changes. Receive `null` when cleared.
marginRightnumberautoEnsure there is enough space for the brush handles when using secondary axes.

Implementation tips

  • Persist the brush domain in parent state so you can apply it to `Chart.XAxis` or other filters.
  • Provide a reset affordance whenever the brush is active to restore the default domain quickly.
  • Large datasets benefit from throttling updates triggered by the brush callback; debounce if you pipe the selection into network requests.