Docs/Cartesian Components/XAxis

XAxis

XAxis renders the horizontal axis of a cartesian chart (or vertical, if the chart layout is vertical). It can display categorical labels or numeric ticks, with customizable formatting and tick intervals.

import { BarChart, Bar, XAxis, YAxis, CartesianGrid } from "solid-recharts";

<BarChart width={500} height={300} data={data}>
  <CartesianGrid strokeDasharray="3 3" />
  <XAxis dataKey="month" angle={-45} />
  <YAxis />
  <Bar dataKey="value" fill="#8884d8" />
</BarChart>;
XAxis
axes-custom-ticks.tsxOpen ↗
Loading source...

Props

PropTypeDefaultDescription
dataKeystring | function—The key (or accessor function) for the data field to plot
type"number" | "category"auto-detectedScale type: categorical or numeric
domain[number, number] | [string, string]autoMin/max values for numeric domains
ticksnumber[] | string[]auto-generatedExplicit tick positions/labels to render
tickFormatter(value) => stringidentityFunction to format tick labels, e.g. abbreviating thousands to "4k"
tickCountnumber5Suggested number of ticks (for numeric axes)
intervalnumber | "preserveStartEnd" | "equidistantPreserveStartEnd"0Tick sampling strategy
anglenumber0Rotation angle in degrees for tick labels
hidebooleanfalseHides the axis, ticks, and labels
xAxisIdstring | number0Unique identifier to bind series to this axis (via xAxisId)
labelstring | object—Axis title, or a <Label> child element

All other recharts XAxis props are supported; see the recharts XAxis docs for the complete reference.

Notes

  • When type is omitted, it defaults to "category" for text values and "number" for numeric values.
  • The tickFormatter is applied only to the rendered labels, not to the underlying scale calculations.
  • Use xAxisId to bind multiple series (Line, Bar, etc.) to the same axis when you have more than one X-axis.
  • allowDataOverflow allows the axis to extend beyond the data min/max.
  • Use angle with textAnchor="end" and an increased height to avoid label overlap on rotated ticks.

See also