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.
Valid Children
XAxis
YAxis
ReferenceArea
ReferenceDot
ReferenceLine
Brush
CartesianGrid
Legend
GraphingTooltip
Bar