Brush

Documentation Index

Fetch the complete documentation index at: /llms.txt. Use this file to discover all available pages before exploring further.

A zoom brush that filters the chart down to a draggable range of the data.

Usage

Add <EvilAreaChart.Brush /> as a child of the chart root. Its presence renders the brush footer โ€” a miniature of the full dataset with a draggable selection window over it. Narrowing that window filters the main chart to the selected range; the miniature always keeps showing everything, so you never lose your place.

Set xDataKey on the root so the handles can label themselves with the value under each edge.

import { EvilAreaChart } from "@/components/evilcharts/charts/recharts-area-chart";
 
<EvilAreaChart data={data} config={chartConfig} xDataKey="date">
  <EvilAreaChart.XAxis dataKey="date" />
  <EvilAreaChart.Brush formatLabel={(value) => String(value)} />
  <EvilAreaChart.Area dataKey="desktop" variant="gradient" />
</EvilAreaChart>;

Example

<EvilAreaChart.Brush />

Supported Charts

The brush is available on the cartesian charts โ€” EvilAreaChart, EvilLineChart, EvilBarChart, and EvilComposedChart. Attach it exactly the same way on each:

<EvilLineChart.Brush />
<EvilBarChart.Brush />
<EvilComposedChart.Brush />

The miniature mirrors the chart it belongs to. Area and composed charts draw filled areas, line charts draw strokes only, and bar charts draw rounded bars โ€” and it inherits the parent chart's curveType, stacking, bar radius, and series colors, so the footer always reads as the same chart in small.

The brush is hidden while the chart is in its loading state, and it never renders for the non-cartesian charts (pie, radar, radial, sankey), which have no continuous axis to zoom.

Reacting to the Range

Filtering the chart is automatic โ€” the root already slices its data to the selection. Pass onChange when something outside the chart needs to follow along, such as a heading that reports the visible window:

const [range, setRange] = useState({ startIndex: 0, endIndex: data.length - 1 });
 
<EvilAreaChart data={data} config={chartConfig} xDataKey="date">
  <EvilAreaChart.Brush onChange={setRange} />
  <EvilAreaChart.Area dataKey="desktop" variant="gradient" />
</EvilAreaChart>;
 
// data[range.startIndex].date โ†’ data[range.endIndex].date

onChange fires with data indices, not values, so look the labels up on your own rows.

API Reference

Brush

Composed as a child of the chart root. It renders nothing itself โ€” its presence turns the brush footer on, and its props configure it.

PropTypeDefaultDescription
heightnumber56

Height of the brush preview strip in pixels.

formatLabel(value: unknown, index: number) => stringโ€“

Formats the range-handle labels from the xDataKey value under each edge. Defaults to the raw value.

onChange(range: { startIndex: number; endIndex: number }) => voidโ€“

Fires as the selection moves, with the inclusive data indices of the visible range.

Root
PropTypeDefaultDescription
xDataKeystringโ€“

The data key the handle labels read from. Without it the handles fall back to raw indices.