✨ Reflex is in Hosting Alpha! Learn more here. ✨
DocsBlogGallery

Search documentation...

/

Star

13k+

[ Learn ]

[ Concepts ]

[ Reference ]

RadarChart


A radar chart shows multivariate data of three or more quantitative variables mapped onto an axis.

For a radar chart we must define an rx.recharts.radar() component for each set of values we wish to plot. Each rx.recharts.radar() component has a data_key which clearly states which variable in our data we are plotting. In this simple example we plot the A column of our data against the subject column which we set as the data_key in rx.recharts.polar_angle_axis.

rx.recharts.radar_chart(
    rx.recharts.radar(
        data_key="A",
        stroke="#8884d8",
        fill="#8884d8",
    ),
    rx.recharts.polar_grid(),
    rx.recharts.polar_angle_axis(data_key="subject"),
    data=data,
)

We can also add two radars on one chart by using two rx.recharts.radar components.

rx.recharts.radar_chart(
    rx.recharts.radar(
        data_key="A",
        stroke="#8884d8",
        fill="#8884d8",
    ),
    rx.recharts.radar(
        data_key="B",
        stroke="#82ca9d",
        fill="#82ca9d",
        fill_opacity=0.6,
    ),
    rx.recharts.polar_grid(),
    rx.recharts.polar_angle_axis(data_key="subject"),
    rx.recharts.legend(),
    data=data,
)

Dynamic Data


Chart data tied to a State var causes the chart to automatically update when the state changes, providing a nice way to visualize data in response to user interface elements. View the "Data" tab to see the substate driving this radar chart of character traits.

Strength

15

Dexterity

15

Constitution

15

Intelligence

15

Wisdom

15

Charisma

15

Remaining points: 10

rx.hstack(
    rx.recharts.radar_chart(
        rx.recharts.radar(
            data_key="value",
            stroke="#8884d8",
            fill="#8884d8",
        ),
        rx.recharts.polar_grid(),
        rx.recharts.polar_angle_axis(data_key="trait"),
        data=RadarChartState.traits,
    ),
    rx.vstack(
        rx.foreach(
            RadarChartState.trait_names,
            lambda trait_name, i: rx.hstack(
                rx.text(trait_name, width="7em"),
                rx.slider(
                    value=RadarChartState.traits[i][
                        "value"
                    ].to(int),
                    on_change=lambda value: RadarChartState.set_trait(
                        trait_name, value
                    ),
                    width="25vw",
                ),
                rx.text(RadarChartState.traits[i]["value"]),
            ),
        ),
        rx.text(
            "Remaining points: ",
            RadarChartState.remaining_points,
        ),
    ),
    width="100%",
    height="15em",
)

RadarChart


A Radar chart component in Recharts.


  • Base Event Triggers

← PieScatter →

Copyright © 2023 Pynecone, Inc.