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

Search documentation...

/

Star

13k+

[ Learn ]

[ Concepts ]

[ Reference ]

PieChart


A pie chart is a circular statistical graphic which is divided into slices to illustrate numerical proportion.

For a pie chart we must define an rx.recharts.pie() component for each set of values we wish to plot. Each rx.recharts.pie() component has a data, a data_key and a name_key which clearly states which data and which variables in our data we are tracking. In this simple example we plot value column as our data_key against the name column which we set as our name_key.

rx.recharts.pie_chart(
    rx.recharts.pie(
        data=data01,
        data_key="value",
        name_key="name",
        cx="50%",
        cy="50%",
        fill="#8884d8",
        label=True,
    )
)

We can also add two pies on one chart by using two rx.recharts.pie components.

rx.recharts.pie_chart(
    rx.recharts.pie(
        data=data01,
        data_key="value",
        name_key="name",
        cx="50%",
        cy="50%",
        fill="#82ca9d",
        inner_radius="60%",
    ),
    rx.recharts.pie(
        data=data02,
        data_key="value",
        name_key="name",
        cx="50%",
        cy="50%",
        fill="#8884d8",
        outer_radius="50%",
    ),
    rx.recharts.graphing_tooltip(),
)

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 half-pie chart.

🏆1

🪵1

🥑1

🧱1

rx.hstack(
    rx.recharts.pie_chart(
        rx.recharts.pie(
            data=PieChartState.resources,
            data_key="count",
            name_key="type_",
            cx="50%",
            cy="50%",
            start_angle=180,
            end_angle=0,
            fill="#8884d8",
            label=True,
        ),
        rx.recharts.graphing_tooltip(),
    ),
    rx.vstack(
        rx.foreach(
            PieChartState.resource_types,
            lambda type_, i: rx.hstack(
                rx.button(
                    "-",
                    on_click=PieChartState.decrement(type_),
                ),
                rx.text(
                    type_,
                    PieChartState.resources[i]["count"],
                ),
                rx.button(
                    "+",
                    on_click=PieChartState.increment(type_),
                ),
            ),
        ),
    ),
    width="100%",
    height="15em",
)

PieChart


A Pie chart component in Recharts.


  • Base Event Triggers

← LineRadar →

Copyright © 2023 Pynecone, Inc.