import { cn } from '@/lib/cn' type BarDatum = { label: string value: number sublabel?: string } type Props = { data: BarDatum[] maxBars?: number formatValue?: (v: number) => string barClassName?: string } // Horizontal bar chart using plain Tailwind — không cần thư viện ngoài. export function BarChart({ data, maxBars = 12, formatValue = v => v.toLocaleString('vi-VN'), barClassName }: Props) { const shown = data.slice(0, maxBars) const max = Math.max(1, ...shown.map(d => d.value)) return (
{shown.length === 0 &&
Chưa có dữ liệu
} {shown.map((d, i) => { const pct = (d.value / max) * 100 return (
{d.label} {formatValue(d.value)}
{d.sublabel &&
{d.sublabel}
}
) })}
) }