shadcn.io is not affiliated with official shadcn/ui
Chart examples · Bar
A bar chart with a label for React
A bar chart with each bar's value printed above it.
Use it when every value should be readable at a glance, in a screenshot or a printed report. A LabelList at position="top" prints each month's count above its bar, and a top margin of 20 keeps the tallest label from being clipped. The tooltip still works on hover.
Preview
Installation
FAQ
How are the numbers printed above the bars?
Bar wraps a LabelList with position set to top. It has no dataKey of its own, so the text is the bar's desktop value. offset is 12 and fontSize is 12.
How is the label text colored?
LabelList sets className to fill-foreground. The bars use fill var(--color-desktop) and radius 8. config maps desktop to var(--chart-1) and the label Desktop.
Why is there space above the tallest bar?
BarChart sets margin to { top: 20 }. That inset keeps the top labels inside the chart, including February's 305.
How are the month ticks shortened?
XAxis uses dataKey month and tickFormatter set to formatMonth, which returns the first three characters. axisLine and tickLine are false, and tickMargin is 10.
Related
- A bar chartA bar chart with rounded corners
- A bar chart with a custom labelA horizontal bar chart with the month
- A multiple bar chartA bar chart grouping desktop and mobile
- A horizontal bar chartA bar chart laid out horizontally, with
- A stacked bar chart with a legendA bar chart stacking desktop and mobile
- A simple area chartA single-series area chart with a smooth