Card with a horizontal bar chart ranking five countries by listeners, country names on the axis and values printed at the end of each bar. Client component on recharts 3.8.
"use client"
import { Bar, BarChart, LabelList, XAxis, YAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "@/components/ui/chart"
// The copy: change text here, not in the markup.
const COPY = {
title: "Top countries",
description: "Listeners by country in October",
} as const
const COUNTRIES = [
{ country: "United States", listeners: 4820 },
{ country: "Germany", listeners: 2940 },
{ country: "Japan", listeners: 2310 },
{ country: "Brazil", listeners: 1870 },
{ country: "India", listeners: 1540 },
]
const CHART_CONFIG = {
listeners: { label: "Listeners", color: "var(--chart-2)" },
} satisfies ChartConfig
export default function BarChart02() {
return (
<Card className="mx-auto w-full max-w-md">
<CardHeader>
<CardTitle>
<h2>{COPY.title}</h2>
</CardTitle>
<CardDescription>{COPY.description}</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={CHART_CONFIG}>
<BarChart
accessibilityLayer
data={COUNTRIES}
layout="vertical"
margin={{ right: 48 }}
>
{/* Stock ChartContainer's label color misses recharts 3's label layer. */}
<YAxis
tick={{ fill: "var(--muted-foreground)" }}
dataKey="country"
type="category"
tickLine={false}
axisLine={false}
tickMargin={8}
width={104}
/>
<XAxis dataKey="listeners" type="number" hide />
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel />}
/>
<Bar dataKey="listeners" fill="var(--color-listeners)" radius={6}>
<LabelList
dataKey="listeners"
position="right"
offset={8}
className="fill-foreground"
fontSize={12}
formatter={(value) => Number(value).toLocaleString("en-US")}
/>
</Bar>
</BarChart>
</ChartContainer>
</CardContent>
</Card>
)
}
pnpm dlx shadcn add @01orbital/bar-chart-02npx shadcn add @01orbital/bar-chart-02yarn shadcn add @01orbital/bar-chart-02bunx --bun shadcn add @01orbital/bar-chart-02Free under the MIT license. Add the @01orbital registry to components.json once (install guide), then run the command.
It lands at components/blocks/charts/bar-chart-02/index.tsx, as source you own and edit.
import BarChart02 from "@/components/blocks/charts/bar-chart-02"
export default function Example() {
return <BarChart02 />
}npm: recharts@3.8.0. The CLI installs them for you.
Registry pieces it installs with it:
cardchartExercise Minutes
Card with a two-line chart comparing this week's exercise minutes against the average by day, both drawn in primary ink with the average at half strength. Client component on recharts 3.8.
Labelled Line Chart Card
Card with a single-series line chart of average session minutes by month, each point labelled with its value, and a footer note on the trend. Client component on recharts 3.8.