For AI agents: the complete documentation index is at llms.txt. Markdown versions are available by appending .md or sending Accept: text/markdown.
Reflex Logo
Docs Logo
Library

/

Graphing

/

General

/

Cartesiangrid

Cartesian Grid

The Cartesian Grid is a component in Recharts that provides a visual reference for data points in charts. It helps users to better interpret the data by adding horizontal and vertical lines across the chart area.

Simple Example

The stroke_dasharray prop in Recharts is used to create dashed or dotted lines for various chart elements like lines, axes, or grids. It's based on the SVG stroke-dasharray attribute. The stroke_dasharray prop accepts a comma-separated string of numbers that define a repeating pattern of dashes and gaps along the length of the stroke.

  • stroke_dasharray="5,5": creates a line with 5-pixel dashes and 5-pixel gaps
  • stroke_dasharray="10,5,5,5": creates a more complex pattern with 10-pixel dashes, 5-pixel gaps, 5-pixel dashes, and 5-pixel gaps

Here's a simple example using it on a Line component:

Hidden Axes

A cartesian_grid component can be used to hide the horizontal and vertical grid lines in a chart by setting the horizontal and vertical props to False. This can be useful when you want to show the grid lines only on one axis or when you want to create a cleaner look for the chart.

Custom Grid Lines

The horizontal_points and vertical_points props allow you to specify custom grid lines on the chart, offering fine-grained control over the grid's appearance.

These props accept arrays of numbers, where each number represents a pixel offset:

  • For horizontal_points, the offset is measured from the top edge of the chart
  • For vertical_points, the offset is measured from the left edge of the chart
Important: The values provided to these props are not directly related to the axis values. They represent pixel offsets within the chart's rendering area.

Here's an example demonstrating custom grid lines in a scatter chart:

Use these props judiciously to enhance data visualization without cluttering the chart. They're particularly useful for highlighting specific data ranges or creating visual reference points.

API Reference

rx.recharts.CartesianGrid

A CartesianGrid component in Recharts.

Props

PropTypeDescription
x
int

The x-coordinate of grid.

y
int

The y-coordinate of grid.

width
int

The width of grid.

height
int

The height of grid.

horizontal
bool

The horizontal line configuration.

vertical
bool

The vertical line configuration.

vertical_points
Sequence

The x-coordinates in pixel values of all vertical lines.

horizontal_points
Sequence

The x-coordinates in pixel values of all vertical lines.

fill
Union[str, Color]

The background of grid.

fill_opacity
float

The opacity of the background used to fill the space between grid lines.

stroke_dasharray
str

The pattern of dashes and gaps used to paint the lines of the grid.

stroke
Union[str, Color]

the stroke color of grid.

Built with Reflex