Makes charts responsive to container size changes. The ResponsiveContainer component adjusts its width and height based on the size of its parent element, creating charts that adapt to different screen sizes. This component uses the ResizeObserver API to monitor changes to the size of its parent element. For older browsers, you may need to include a polyfill.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/recharts/recharts/llms.txt
Use this file to discover all available pages before exploring further.
Usage
Props
Dimensions
The width of the container.Can be a number (pixels) or a percent string like “100%”.
The height of the container.Can be a number (pixels) or a percent string like “100%”.
The minimum width of the container.Can be a number (pixels) or a CSS string value.
The minimum height of the container.Can be a number (pixels) or a CSS string value.
The maximum height of the container, in pixels.
Aspect ratio
Width / height ratio.If specified, the height is calculated by width / aspect.
Initial state
The initial width and height of the container.Used before the ResizeObserver detects the actual size.Format:
{ width: number, height: number }Performance
If specified as a positive number, a debounced function is used to handle resize events.Value is in milliseconds.
Callback providing the updated chart width and height values.Signature:
(width: number, height: number) => voidContent
The content of the container.Can contain multiple charts, and they will all share the same dimensions.
Styling
CSS styles applied to the container element.Note: width, height, minWidth, minHeight, and maxHeight are excluded as they are controlled by dedicated props.
The HTML element’s class name.
Other
Unique identifier of this component.Used as an HTML attribute
id.Notes
- ResponsiveContainer uses ResizeObserver to monitor size changes. Ensure browser support or include a polyfill.
- If you nest ResponsiveContainer inside another ResponsiveContainer, the inner one will not add another layer of responsiveness.
- When static width and height are provided (not percentages), ResponsiveContainer may skip rendering the monitoring div and provide dimensions directly.