Native Solid 2 fork of solid-recharts (MIT, © Thomas Guehenneux), derived from Recharts (MIT, © recharts). Adapted documentation; neither project endorses this fork.
Responsive charts and SSR
ResponsiveContainer
ResponsiveContainer measures its parent with a ResizeObserver and passes the size to the chart. The parent must have a defined size: a fixed height, or a flex or grid track. A parent with height: auto and a percentage height renders a 0×0 chart.
| Prop | Type | Default | Description |
|---|---|---|---|
width, height | number | string | — | Pixels or a percentage of the parent |
aspect | number | — | Keep a width-to-height ratio |
minWidth, minHeight, maxHeight | number | string | — | Bounds while resizing |
debounce | number | 0 | Milliseconds to wait before applying a new size |
onResize | (width, height) => void | — | Called after a resize |
initialDimension | { width, height } | — | Size used before the first measurement, including on the server |
Server rendering
A server has no layout, so a responsive chart cannot measure itself there. Give the server something to draw:
- A chart with a fixed
widthandheightrenders real SVG on the server, and its root SVG hydrates in place. Animated series may still replace their own paths in the browser, and the server geometry is only final under the recipe below. - A
ResponsiveContainerwithinitialDimensionrenders at that size on the server, then measures and redraws on the client. - A
ResponsiveContainerwithoutinitialDimensionrenders an empty measurement state on the server and draws on the client. This is intentional: the package does not invent dimensions.
Next-suite measured layout
With Legend position supplied and the default mount, the chart wrapper owns the server-rendered legend HTML. Its measured box is initially 0 × 0, and the first client styles retain that state before applying browser measurements. Outside legends then reserve their measured size; inside positions reserve no plot space and their placement does not depend on that measurement. Legends without position and those using an explicit custom portal retain their existing DOM-only path; this does not add server markup for those paths. position overrides align and verticalAlign; layout="auto" chooses vertical for left, right, insideLeft, and insideRight, horizontal otherwise.
XAxis height="auto" uses 30px on the server and first client render. After mount it measures rendered ticks and a string label, then rounds the tallest tick height plus tickSize, tickMargin, and the label height plus 5px when present. Custom render-function labels are excluded from this measurement. Pass custom JSX through a render function, not as a raw JSX label value. Requested numeric heights and tick positions remain unchanged. Shared server clip production now follows axis registration: for a 300px chart with 5px top/bottom margins and a numeric 30px X axis, the plot clip is correctly 260px rather than the previous erroneous 290px. This correction is not byte-identical SSR markup or clip output. Automatic sizing is browser-measured, not server-final; use the bounded recipe below when final server geometry is required.
Sankey title and desc supply the root SVG's accessible name and description, including server output. accessibilityLayer enables its accessibility attributes. These attributes do not require browser geometry; see the live Sankey example.
Server geometry needs explicit axes
The server renders a chart in one pass, before axes and series have registered with each other. Charts that rely on automatic domains or automatic axis sizes are not supported on the server: their client render is correct, but their server HTML is not. With an automatic Y domain, for example, two stacked Bar series are drawn against different domains and numeric Y-axis ticks are missing; with automatic axis sizes, category labels do not line up with the bars.
The following bounded recipe for Cartesian charts is regression-tested to give the same tick positions and series geometry before and after hydration:
- Declare the axes before the series, the category axis first. Do not reorder them.
- Reserve the axis gutters in the chart's
margin, and set the axes' own size to zero (height={0}onXAxis,width={0}onYAxis) so the space is not reserved twice. - Give the category axis
scale="band", so its labels sit at the centers of the bars. - Give the value axis an explicit
domainandallowDataOverflow, so the bound you set is authoritative. Values outside it are clipped to the plot area rather than widening the axis, so choose a domain that covers your largest stacked total. - Set
interval={0}on both axes. The browser measures label text and hides labels that would overlap; the server cannot measure text, so it keeps every label. Withinterval={0}both keep every label at the same position. Make sure your labels fit without overlapping.
On the server this renders the A and B labels centered under their bars, the value ticks 0, 15, 30, 45 and 50, and the four stacked bars at their final positions, all inside the 430 × 260 plot area that the margin leaves. After hydration the labels, ticks and bars keep the same positions.
Every chart example on this site uses initialDimension, so the exported HTML and the Markdown twin of each page contain a server-rendered chart. Most of those examples use automatic domains, so their server geometry and numeric ticks are not final; the client redraws them when it activates.
Theming
Series accept any CSS color. Themes tokens (var(--accent-9), var(--gray-a6), …) follow the nearest Theme, so a chart inside a dark or custom-accent theme updates without new props. Charts does not depend on Themes; outside a Theme, give token colors a plain fallback (var(--accent-9, royalblue)), as the recipe above does.