Charts
Beautiful charts. Built using Recharts. Copy and paste into your apps.
A collection of chart components that you can copy and paste into your apps. Charts are designed to look great out of the box. They work well with the other components and are fully customizable to fit your project.
For an overview of whats available, checkout the Charts page.
Component
Reflex wraps Recharts under the hood. This means you build your own charts using Recharts components and only bring in your theme tokens and custom components like chart_tooltip when and where you need it.
chart
We do not wrap Recharts. This means you're not locked into an abstraction. When a new Recharts version is released, you can follow the official upgrade path to upgrade your charts.
Installation
buridan/ui provides a custom chart_tooltip that can be used to match the overall theme tokens generated.
Command
Command
Manual
Manual
uv
Your First Chart
Let's build your first chart. We'll build a bar chart, add a grid, axis, tooltip and legend.
Defining your data
The following data represents the number of desktop and mobile users for each month.
Note: All of our examples use static data in a specific data structure. You are not limited to either static data or the structure. For dynamic data, use rx.State instead.
example_chart.py
Build your chart
You can now build your chart using Recharts components.
Add an Axis
To add an x-axis to the chart, we'll use the rx.recharts.x_axis() component.
example_chart.py
Add Tooltip
So far we've only used components from Recharts. They look great out of the box thanks to some customization in the chart component.
To add a tooltip, we'll use the custom chart_tooltip and chart_tooltip_content components from chart.
Note: A small comment regarding the custom tooltip. Because of the way Recharts is composed and the way it's wrapped in Reflex, the custom tooltip, as of now, works only for Area, Bar, and Line charts.
To use the custom tooltip, first import it at the top of your chart file.
chart_example.py
Add the component to your chart and pass in the props.
example_chart.py
Hover to see the tooltips. Easy, right? Two components, and we've got a beautiful tooltip.
Add Legend
We'll do the same for the legend. Although there's no API for legends the way we created one for tooltips, the same logic still applies.
Add the component to your chart.
example_chart.py
Desktop
Mobile
Done. You've built your first chart!
Theming
Charts have built-in support for theming. You can use css variables (recommended) or color values in any color format, such as hex, hsl or oklch.
CSS Variables
Define your colors in your CSS file.
assets/globals.css
hex, hsl, or oklch
You can also define your colors directly in the chart component. Use the color format you prefer.
chart_example.py
You can also include colors in your data structure and utlize rx.foreach for more concise codebase.
example_chart.py
Tooltip
A chart tooltip contains a label and swatch type. You can use a combination of these to customize your tooltip.
chart_tooltip.py
Page Views
Page Views
Page Views
Page Views
You can turn on/off any of these using the display prop and customize the indicator style using the swatch prop.
Props
Use the following props to customize the tooltip.
chart_tooltip()
chart_tooltip_content()
chart_tooltip_content() returns a string of Tailwind classes and must be passed to the chart component's class_name, not to chart_tooltip().