shadcn.io is not affiliated with official shadcn/ui
Chart examples · Bar
A horizontal bar chart for React
A bar chart laid out horizontally, with the months on the vertical axis.
Use horizontal bars when the categories have long names or the chart is a ranking. layout="vertical" on BarChart turns the bars sideways, the Y axis lists the months, and the X axis that carries the values is hidden.
Preview
Installation
FAQ
What turns the bars sideways?
BarChart sets layout to vertical. YAxis is type category with dataKey month, and XAxis is type number with dataKey desktop. XAxis also sets hide, so the number scale stays off the chart.
How are the month labels shortened?
YAxis sets tickFormatter to formatMonth, which returns value.slice(0, 3), so January renders as Jan. axisLine and tickLine are false, and tickMargin is 10.
Why is the left margin negative?
BarChart sets margin to { left: -20 }, which pulls the category ticks toward the plot. Bar uses dataKey desktop, fill var(--color-desktop), and radius 5.
Where does the bar color come from?
config sets desktop to the label Desktop and color var(--chart-1). ChartContainer writes --color-desktop, and Bar fills with that variable.
Related
- A bar chartA bar chart with rounded corners
- A bar chart with a custom labelA horizontal bar chart with the month
- A mixed bar chartA horizontal bar chart with a different
- A multiple bar chartA bar chart grouping desktop and mobile
- Basic Data Table with CheckboxesA table of products with a checkbox on
- A stacked bar chart with a legendA bar chart stacking desktop and mobile