useChartWidth

Returns the width of the chart in pixels.

If you are using chart with hardcoded width prop, then the width returned will be the same as the width prop on the main chart element.

If you are using a chart with a ResponsiveContainer, the width will be the size of the chart as the ResponsiveContainer has decided it would be.

If the chart has any axes or legend, the width will be the size of the chart including the axes and legend. Meaning: adding axes and legend will not change the width.

The dimensions do not scale, meaning as user zoom in and out, the width number will not change as the chart gets visually larger or smaller.

Returns undefined if used outside a chart context.

Return value

number | undefined

The width of the chart in pixels, or undefined if not in a chart context.