Monthly Column Bar Chart
Vertical bar chart card for monthly stats: a column chart of sessions with the value printed above each rounded bar, and a footer with a trend sentence, icon and note.
"use client"
import { TrendUpIcon } from "@phosphor-icons/react"
import { Bar, BarChart, CartesianGrid, LabelList, XAxis } from "recharts"
import {
Card,
CardContent,
CardDescription,
CardFooter,
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: "Sessions",
description: "May to October 2026",
trend: "Up 6.4% on September",
note: "Sessions started on any device.",
} as const
const SESSIONS = [
{ month: "May", sessions: 1860 },
{ month: "June", sessions: 2050 },
{ month: "July", sessions: 2370 },
{ month: "August", sessions: 1730 },
{ month: "September", sessions: 2090 },
{ month: "October", sessions: 2224 },
]
const CHART_CONFIG = {
sessions: { label: "Sessions", color: "var(--chart-3)" },
} satisfies ChartConfig
export default function ValueLabeledColumnChart() {
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={SESSIONS} margin={{ top: 24 }}>
<CartesianGrid vertical={false} />
{/* Stock ChartContainer's label color misses recharts 3's label layer. */}
<XAxis
tick={{ fill: "var(--muted-foreground)" }}
dataKey="month"
tickLine={false}
axisLine={false}
tickMargin={10}
tickFormatter={(value: string) => value.slice(0, 3)}
/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel />}
/>
<Bar
dataKey="sessions"
fill="var(--color-sessions)"
radius={[2, 2, 0, 0]}
maxBarSize={16}
>
{/* The printed value carries the number, so the bar need not. */}
<LabelList
dataKey="sessions"
position="top"
offset={10}
className="fill-foreground"
fontSize={12}
formatter={(value) => Number(value).toLocaleString("en-US")}
/>
</Bar>
</BarChart>
</ChartContainer>
</CardContent>
<CardFooter className="flex-col items-start gap-2 text-sm">
<p className="flex items-center gap-2 font-medium">
{COPY.trend}
<TrendUpIcon aria-hidden="true" className="size-4" />
</p>
<p className="text-muted-foreground">{COPY.note}</p>
</CardFooter>
</Card>
)
}
Installation
npx shadcn@latest add @01orbital/value-labeled-column-chartMake it yours
- Its words are in
COPYat the top ofcomponents/blocks/charts/value-labeled-column-chart/index.tsx: change them there, not in the markup. SESSIONSandCHART_CONFIG, also at the top of the file, hold its lists and settings.
Built from
npm: @phosphor-icons/react, recharts@3.8.0. The CLI installs them for you.
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on