Docs/General Components/Text

Text

Text is a low-level SVG <text> component that handles word wrapping, scaling to fit, and multiline layout. It's used internally by axes and labels, but also exported for custom tick labels, axis labels, and other text rendering.

import { Text } from "solid-recharts";

<Text x={0} y={0} width={100} textAnchor="middle" scaleToFit>
  Custom axis tick label
</Text>;

Props

PropTypeDefaultDescription
x, ynumber—SVG coordinates
width, heightnumber | string—Container dimensions; enables word wrapping when set
textAnchor"start" | "middle" | "end" | "inherit""start"Horizontal alignment
verticalAnchor"start" | "middle" | "end""end"Vertical alignment
anglenumber0Rotation in degrees
scaleToFitbooleanfalseShrink/stretch text to fit width
breakAllbooleanfalseBreak at character boundaries (not just words)
maxLinesnumber—Maximum lines before truncation
lineHeightnumber | string"1em"Line spacing
capHeightnumber | string"0.71em"Cap height for vertical centering
fillstring"#808080"Text color
classstring—CSS class (applied as recharts-text)
childrenstring | number—Text content

All SVG text attributes (e.g. dx, dy, fontFamily, fontSize) are supported.

Notes

  • Text is positioned absolutely; parent must define the <svg> or chart context.
  • When width is set, text wraps automatically; maxLines truncates with "…".
  • scaleToFit resizes the entire text block to fit the width, rather than wrapping.
  • Use verticalAnchor="middle" with capHeight to center text vertically.

See also

  • Label — positioned text labels for charts
  • LabelList — multiple labels per series