For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
0
Sponsor

Brush

A zoom brush that filters a cartesian chart to a draggable data range.

ChartGPUPixiJS
PixiJS renderer

Usage

Add <Brush /> inside the chart root. Its presence renders a miniature of the full dataset with a draggable selection window. Narrowing the window filters the main plot while the miniature retains the full context.

Set xDataKey on the root, or dataKey on <XAxis />, so the range labels use the category beneath each handle.

import { ChartcnAreaChart } from "@/components/chart/area-chart";
 
<ChartcnAreaChart data={data} config={chartConfig} xDataKey="month">
  <ChartcnAreaChart.XAxis dataKey="month" />
  <ChartcnAreaChart.Brush startIndex={2} endIndex={10} />
  <ChartcnAreaChart.Area dataKey="desktop" />
</ChartcnAreaChart>;

Example

<ChartcnAreaChart.Brush />

Drag either handle to resize the range, or drag the selected region to move it without changing its width. Handle labels fade in while the pointer is over the brush. Mouse, touch, and pen input are supported.

Supported Charts

Brush is available on the cartesian charts: Area, Line, Bar, and Composed Chart. Attach it the same way to each root.

<ChartcnLineChart.Brush />
<ChartcnBarChart.Brush />
<ChartcnComposedChart.Brush />

The miniature uses the full dataset and inherits the parent chart's series colors and selection opacity. The primary plot, x-axis labels, tooltip values, and range labels update to the same visible indices.

Brush is hidden from non-cartesian charts because pie, scatter, financial, and heatmap plots do not share this category-window interaction.

Reacting to the Range

Filtering is automatic. Pass onBrushChange when content outside the chart must follow the selection.

const [range, setRange] = useState({
  startIndex: 0,
  endIndex: data.length - 1,
});
 
<ChartcnAreaChart
  data={data}
  config={chartConfig}
  onBrushChange={setRange}
  xDataKey="month"
>
  <ChartcnAreaChart.Brush />
  <ChartcnAreaChart.Area dataKey="desktop" />
</ChartcnAreaChart>;

onBrushChange returns inclusive data indices, so external content can read the corresponding rows directly.

API Reference

Brush

PropTypeDefaultDescription
startIndexnumber0Inclusive index at the left edge of the range.
endIndexnumberLast data indexInclusive index at the right edge.

Root

PropTypeDefaultDescription
xDataKeystring-Data key used for axis and range labels.
onBrushChange(range: { startIndex: number; endIndex: number }) => void-Fires as the selected range changes.
showBrushbooleanfalseEnables Brush without composing the child part.