Docs/Cartesian Components/CartesianGrid

CartesianGrid

CartesianGrid renders the horizontal and vertical grid lines (and optionally background stripes) in cartesian charts. It automatically aligns with axis ticks or custom positions.

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

<LineChart width={500} height={300} data={data}>
  <CartesianGrid strokeDasharray="3 3" />
  <XAxis dataKey="name" />
  <YAxis />
</LineChart>;
LineChart
line-basic.tsxOpen ↗
Loading source...

Props

PropTypeDefaultDescription
strokeDasharraystring | number"none"Dash pattern, e.g. "3 3" for dashed lines
strokestring"#ccc"Grid line color
horizontalbooleantrueShow or hide horizontal grid lines
verticalbooleantrueShow or hide vertical grid lines
syncWithTicksbooleanfalseAlign grid lines to axis tick positions (not just min/max)
fillstring"none"Background fill color of the chart area
horizontalFillstring[][]Colors for alternating horizontal stripes
verticalFillstring[][]Colors for alternating vertical stripes
horizontalPointsnumber[]autoCustom y-coordinates for horizontal grid lines
verticalPointsnumber[]autoCustom x-coordinates for vertical grid lines
xAxisIdstring | number0XAxis to sync grid lines with
yAxisIdstring | number0YAxis to sync grid lines with

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

Notes

  • Without syncWithTicks={true}, grid lines are drawn at the axis domain min and max, plus any extra tick positions beyond those bounds.
  • Set syncWithTicks={true} to draw grid lines only at axis tick positions.
  • Use strokeDasharray="3 3" to create a dashed line effect (values are SVG dash length and space length).
  • horizontalFill and verticalFill accept arrays of colors that repeat in order. A two-color array creates alternating stripes.
  • The grid layer is rendered behind the chart data; use the zIndex prop to adjust if needed.

See also