ResponsiveContainer
ResponsiveContainer wraps a chart and automatically sizes it to match its parent element's dimensions. The parent must have a defined size (via CSS or inline styles).
import { LineChart, Line, XAxis, YAxis, ResponsiveContainer } from "solid-recharts";
<div style={{ width: "100%", height: 300 }}>
<ResponsiveContainer width="100%" height="100%">
<LineChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<Line dataKey="uv" stroke="#8884d8" />
</LineChart>
</ResponsiveContainer>
</div>;
Loading source...
Props
| Prop | Type | Default | Description |
|---|---|---|---|
width | number | string | — | Width as pixels or percentage; omit if chart fills parent |
height | number | string | — | Height as pixels or percentage; omit if chart fills parent |
aspect | number | — | Aspect ratio to maintain (e.g., 1 for square, 16 / 9 for video) |
minWidth | number | string | 0 | Minimum width when the container shrinks |
minHeight | number | string | — | Minimum height when the container shrinks |
maxHeight | number | — | Maximum height when the container grows |
debounce | number | 0 | Milliseconds to delay resize callbacks (0 = immediate) |
onResize | (w, h) => void | — | Called when the container is resized |
initialDimension | { width, height } | { 800, 600 } | Starting size before ResizeObserver takes a measurement |
class | string | — | CSS class for the outer wrapper div |
style | JSX.CSSProperties | — | Inline styles for the outer wrapper |
ref | HTMLDivElement | fn | — | Reference to the outer wrapper DOM element |
Notes
- The parent container must have a defined width and height. If the parent is a flex/grid container with
flex: 1or similar, that works; if it hasheight: auto, charts will render at 0×0. - Pass
width="100%"andheight="100%"to fill the parent; omit them if the container takes up all available space (e.g., full-window app). aspectmaintains a ratio;minHeight/minWidthprevent the chart from becoming too small on resize.debounce > 0reduces how oftenonResizefires during window resize (useful for expensive layout updates).