Native Solid 2 fork of solid-recharts (MIT, © Thomas Guehenneux), derived from Recharts (MIT, © recharts). Adapted documentation; neither project endorses this fork.

BarChart

BarChart is the cartesian container for Bar series. It owns the chart's layout, scales, and interaction state; children like XAxis, CartesianGrid and Tooltip register themselves into it.

Monthly visitors and signupsJanFebMarAprMayJunReporting month
() => {
const data = [
{ month: "Jan", visitors: 4000, signups: 2400, revenue: 2400 },
{ month: "Feb", visitors: 3000, signups: 1398, revenue: 2210 },
{ month: "Mar", visitors: 2000, signups: 3800, revenue: 2290 },
{ month: "Apr", visitors: 2780, signups: 3908, revenue: 2000 },
{ month: "May", visitors: 1890, signups: 4800, revenue: 2181 },
{ month: "Jun", visitors: 2390, signups: 3800, revenue: 2500 },
];
return <ResponsiveContainer width="100%" height={300} initialDimension={{ width: 560, height: 300 }}>
<BarChart data={data} title="Monthly visitors and signups">
<CartesianGrid strokeDasharray="3 3" stroke="var(--gray-a6)" vertical={false} />
<XAxis dataKey="month" height="auto" angle={-35} label="Reporting month" />
<YAxis />
<Tooltip />
<Legend position="bottom" offset={8} layout="auto" />
<Bar dataKey="visitors" fill="var(--accent-9)" radius={[4, 4, 0, 0]} />
<Bar dataKey="signups" fill="var(--teal-9)" radius={[4, 4, 0, 0]} />
</BarChart>
</ResponsiveContainer>;
}

Props

PropTypeDefaultDescription
dataobject[]—Source data array, one entry per x position
width, heightnumber—Fixed size (omit when inside ResponsiveContainer)
layout"horizontal" | "vertical""horizontal"Direction of the independent axis
margin{ top, right, bottom, left }{ 5, 5, 5, 5 }Space around the plot area
syncIdstring—Sync tooltip/brush across charts sharing the id
onClick, onMouseMove, …function—Chart-level mouse events with the active payload

The base API follows Recharts 3.9.2 (reference commit b3451050), with the selected next-suite additions; this is not full Recharts 3.10.1 parity. See the Recharts BarChart reference.

Notes

  • Multiple Bar children are rendered side-by-side (grouped) unless you set a stackId.
  • Set the same stackId on two or more Bar children to stack them.
  • Use the radius prop to round the top corners: radius={[4, 4, 0, 0]}.
  • Set syncId on two charts to mirror tooltips and brushes between them.

Legend and axis layout

This example places the legend outside the plot with position="bottom" and offset={8}. position accepts the exported CartesianPosition type and overrides align/verticalAlign; omitted position preserves their existing behavior. offset defaults to 0. layout defaults to "auto": vertical for left, right, insideLeft, and insideRight, horizontal otherwise.

Outside legends reserve their measured size; inside legends reserve none. With position supplied and the default mount, the wrapper renders legend HTML on the server, and the first client styles retain its zero measured box before measurement. Outside placement adjusts after browser measurement; inside placement is measurement-independent. No-position legends and explicit custom portals retain the existing DOM-only path, without server legend markup. The playground switches between inside and outside placement.

XAxis height="auto" uses a 30px server/first-client fallback, then measures rotated tick labels and the string label. The rounded height includes the tallest tick, tickSize, tickMargin, and the label's height plus 5px when present. Custom render-function labels do not use auto measurement. Pass custom JSX through a render function, not as a raw JSX label value. Requested numeric heights and tick positions are unchanged, but corrected server plot clips can change SSR markup. Automatic height is not server-final geometry. See LineChart's layout details and SSR.

See also

  • Bar — the series component and its shape/label options
  • XAxis · YAxis
  • ComposedChart — mix bars with lines and areas