Docs/General Components/ResponsiveContainer

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>;
LineChart
line-basic.tsxOpen ↗
Loading source...

Props

PropTypeDefaultDescription
widthnumber | string—Width as pixels or percentage; omit if chart fills parent
heightnumber | string—Height as pixels or percentage; omit if chart fills parent
aspectnumber—Aspect ratio to maintain (e.g., 1 for square, 16 / 9 for video)
minWidthnumber | string0Minimum width when the container shrinks
minHeightnumber | string—Minimum height when the container shrinks
maxHeightnumber—Maximum height when the container grows
debouncenumber0Milliseconds 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
classstring—CSS class for the outer wrapper div
styleJSX.CSSProperties—Inline styles for the outer wrapper
refHTMLDivElement | 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: 1 or similar, that works; if it has height: auto, charts will render at 0×0.
  • Pass width="100%" and height="100%" to fill the parent; omit them if the container takes up all available space (e.g., full-window app).
  • aspect maintains a ratio; minHeight/minWidth prevent the chart from becoming too small on resize.
  • debounce > 0 reduces how often onResize fires during window resize (useful for expensive layout updates).

See also

  • LineChart — the most common chart parent
  • Legend — legend layout depends on chart dimensions