Axis

The Axis component in Recharts is a powerful tool for customizing and configuring the axes of your charts. It provides a wide range of props that allow you to control the appearance, behavior, and formatting of the axis. Whether you're working with an AreaChart, LineChart, or any other chart type, the Axis component enables you to create precise and informative visualizations.

Basic Example

def axis_simple():
    return rx.recharts.area_chart(
        rx.recharts.area(
            data_key="uv",
            stroke=rx.color("accent", 9),
            fill=rx.color("accent", 8),
        ),
        rx.recharts.x_axis(
            data_key="name",
            label={"value": "Pages", "position": "bottom"},
        ),
        rx.recharts.y_axis(
            data_key="uv",
            label={
                "value": "Views",
                "angle": -90,
                "position": "left",
            },
        ),
        data=data,
        width="100%",
        height=300,
        margin={
            "bottom": 40,
            "left": 40,
            "right": 40,
        },
    )

Multiple Axes

Multiple axes can be used for displaying different data series with varying scales or units on the same chart. This allows for a more comprehensive comparison and analysis of the data.

def multi_axis():
    return rx.recharts.area_chart(
        rx.recharts.area(
            data_key="uv",
            stroke="#8884d8",
            fill="#8884d8",
            y_axis_id="left",
        ),
        rx.recharts.area(
            data_key="pv",
            y_axis_id="right",
            type_="monotone",
            stroke="#82ca9d",
            fill="#82ca9d",
        ),
        rx.recharts.x_axis(data_key="name"),
        rx.recharts.y_axis(data_key="uv", y_axis_id="left"),
        rx.recharts.y_axis(
            data_key="pv",
            y_axis_id="right",
            orientation="right",
        ),
        rx.recharts.graphing_tooltip(),
        rx.recharts.legend(),
        data=data,
        width="100%",
        height=300,
    )

Choosing Location of Labels for Axes

The axes label can take several positions. The example below allows you to try out different locations for the x and y axis labels.

X Label Position:

X Label Offset:

Y Label Position:

Y Label Offset:

def axis_labels():
    return rx.vstack(
        rx.recharts.area_chart(
            rx.recharts.area(
                data_key="uv",
                stroke=rx.color("accent", 9),
                fill=rx.color("accent", 8),
            ),
            rx.recharts.x_axis(
                data_key="name",
                label={
                    "value": "Pages",
                    "position": AxisState.x_axis_postion,
                    "offset": AxisState.x_axis_offset,
                },
            ),
            rx.recharts.y_axis(
                data_key="uv",
                label={
                    "value": "Views",
                    "angle": -90,
                    "position": AxisState.y_axis_postion,
                    "offset": AxisState.y_axis_offset,
                },
            ),
            data=data,
            width="100%",
            height=300,
            margin={
                "bottom": 40,
                "left": 40,
                "right": 40,
            },
        ),
        rx.hstack(
            rx.text("X Label Position: "),
            rx.select(
                AxisState.label_positions,
                value=AxisState.x_axis_postion,
                on_change=AxisState.set_x_axis_postion,
            ),
            rx.text("X Label Offset: "),
            rx.select(
                AxisState.label_offsets,
                value=AxisState.x_axis_offset.to_string(),
                on_change=AxisState.set_x_axis_offset,
            ),
            rx.text("Y Label Position: "),
            rx.select(
                AxisState.label_positions,
                value=AxisState.y_axis_postion,
                on_change=AxisState.set_y_axis_postion,
            ),
            rx.text("Y Label Offset: "),
            rx.select(
                AxisState.label_offsets,
                value=AxisState.y_axis_offset.to_string(),
                on_change=AxisState.set_y_axis_offset,
            ),
        ),
        width="100%",
    )

API Reference

rx.recharts.XAxis

An XAxis component in Recharts.

PropType | ValuesDefault
orientation
"top" | "bottom"
"bottom"
x_axis_id
Union[str, int]
0
include_hidden
bool
False
angle
int
0
padding
Dict[str, int]
{"left": 0, "right": 0}
data_key
Union[str, int]
hide
bool
False
width
Union[str, int]
height
Union[str, int]
type_
"number" | "category"
interval
"preserveStart" | "preserveEnd" | ...
"preserveEnd"
allow_decimals
bool
True
allow_data_overflow
bool
False
allow_duplicated_category
bool
True
domain
List
[0, "auto"]
axis_line
bool
True
mirror
bool
False
reversed
bool
False
label
Union[str, int, Dict]
scale
"auto" | "linear" | ...
"auto"
unit
Union[str, int]
name
Union[str, int]
ticks
List
tick
bool
tick_count
int
5
tick_line
bool
True
tick_size
int
6
min_tick_gap
int
5
stroke
Union[str, Color]
rx.color("gray", 9)
text_anchor
"start" | "middle" | ...
"middle"

Event Triggers

See the full list of default event triggers

rx.recharts.YAxis

A YAxis component in Recharts.

PropType | ValuesDefault
orientation
"left" | "right"
"left"
y_axis_id
Union[str, int]
0
padding
Dict[str, int]
{"top": 0, "bottom": 0}
data_key
Union[str, int]
hide
bool
False
width
Union[str, int]
height
Union[str, int]
type_
"number" | "category"
interval
"preserveStart" | "preserveEnd" | ...
"preserveEnd"
allow_decimals
bool
True
allow_data_overflow
bool
False
allow_duplicated_category
bool
True
domain
List
[0, "auto"]
axis_line
bool
True
mirror
bool
False
reversed
bool
False
label
Union[str, int, Dict]
scale
"auto" | "linear" | ...
"auto"
unit
Union[str, int]
name
Union[str, int]
ticks
List
tick
bool
tick_count
int
5
tick_line
bool
True
tick_size
int
6
min_tick_gap
int
5
stroke
Union[str, Color]
rx.color("gray", 9)
text_anchor
"start" | "middle" | ...
"middle"

rx.recharts.ZAxis

A ZAxis component in Recharts.

PropType | ValuesDefault
data_key
Union[str, int]
z_axis_id
Union[str, int]
0
range
List
[10, 10]
unit
Union[str, int]
name
Union[str, int]
scale
"auto" | "linear" | ...
"auto"