shadcn.io is not affiliated with official shadcn/ui
Chart examples · Bar
A mixed bar chart for React
A horizontal bar chart with a different color for each browser.
Use it to compare categories that each have their own color. The bars run horizontally, each browser's row carries its fill, and the Y axis shows the browser names from the chart config.
Preview
Installation
FAQ
How does each bar get a different color?
Each row sets fill to a variable such as var(--color-chrome). config maps chrome, safari, firefox, edge, and other to --chart-1 through --chart-5. Bar sets dataKey to visitors and radius to 5, and leaves fill to the row.
What makes the bars horizontal?
BarChart sets layout to vertical and margin to { left: 0 }. YAxis is type category with dataKey browser. XAxis is type number with dataKey visitors and hide.
How do the ticks get names like Chrome?
YAxis sets tickFormatter to formatBrowser, which returns chartConfig[value].label, or the raw key when that label is missing. axisLine and tickLine are false, and tickMargin is 10.
What does the tooltip show?
ChartTooltipContent sets hideLabel, and cursor is false. The name comes from the browser key in config, and the value is visitors. config also labels visitors as Visitors.
Related
- A bar chartA bar chart with rounded corners
- A horizontal bar chartA bar chart laid out horizontally, with
- A bar chart with an active barA bar chart of visitors by browser with
- A bar chart with negative valuesA bar chart with bars above and below
- A simple pie chartA pie chart of visitors by browser, each
- A multiple bar chartA bar chart grouping desktop and mobile