Reflex Cloud - Fast, secure & scalable hosting. One command to deploy.

Bar Chart

A bar chart presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent.

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

Simple Example

Multiple Bars

Multiple bars can be placed on the same bar_chart, using multiple rx.recharts.bar() components.

Ranged Charts

You can also assign a range in the bar by assiging the data_key in the rx.recharts.bar to a list with two elements, i.e. here a range of two temperatures for each date.

Stateful Charts

Here is an example of a bar graph with a State. Here we have defined a function randomize_data, which randomly changes the data for both graphs when the first defined bar is clicked on using on_click=BarState.randomize_data.

Example with Props

Here's an example demonstrates how to customize the appearance and layout of bars using the bar_category_gap, bar_gap, bar_size, and max_bar_size props. These props accept values in pixels to control the spacing and size of the bars.

Vertical Example

The layout prop allows you to set the orientation of the graph to be vertical or horizontal, it is set horizontally by default.

Include margins around your graph to ensure proper spacing and enhance readability. By default, provide margins on all sides of the chart to create a visually appealing and functional representation of your data.

To learn how to use the sync_id, stack_id,x_axis_id and y_axis_id props check out the of the area chart documentation, where these props are all described with examples.

API Reference

rx.recharts.BarChart

A Bar chart component in Recharts.

PropType | ValuesDefault
bar_category_gap
Union[str, int]
"10%"
bar_gap
Union[str, int]
4
bar_size
int
max_bar_size
int
stack_offset
"expand" | "none" | ...
"none"
reverse_stack_order
bool
False
data
List
margin
Dict[str, Any]
sync_id
str
sync_method
"index" | "value"
"index"
layout
"vertical" | "horizontal"
"horizontal"
width
Union[str, int]
"100%"
height
Union[str, int]
"100%"

Valid Children

XAxisYAxisReferenceAreaReferenceDotReferenceLineBrushCartesianGridLegendGraphingTooltipBar

rx.recharts.Bar

A Bar component in Recharts.

PropType | ValuesDefault
stroke
Union[str, Color]
stroke_width
int
fill
Union[str, Color]
Color("accent", 9)
background
bool
False
label
bool
False
stack_id
str
unit
Union[str, int]
min_point_size
int
name
Union[str, int]
bar_size
int
max_bar_size
int
radius
Union[int, List]
0
layout
"vertical" | "horizontal"
data_key
Union[str, int]
x_axis_id
Union[str, int]
0
y_axis_id
Union[str, int]
0
legend_type
"line" | "plainline" | ...
is_animation_active
bool
True
animation_begin
int
0
animation_duration
int
1500
animation_easing
"ease" | "ease-in" | ...
"ease"

Valid Children

CellLabelListErrorBar

Event Triggers

See the full list of default event triggers
TriggerDescription
on_animation_start The customized event handler of animation start
on_animation_end The customized event handler of animation end