NK

Search

Search pages, posts, and components

All components

Bar Chart Mini

Data Display

A compact bar chart whose bars grow in sequence and show values on hover.

1219822142718

Installation

Add it with the shadcn CLI:

$pnpm dlx shadcn@latest add https://nawalkattel.com.np/r/bar-chart-mini.json
Or install manually
  1. 1. Install dependencies

    pnpm add motion clsx tailwind-merge
  2. 2. Copy the component source into components/library/bar-chart-mini.tsx

Props

PropTypeDefaultDescription
datanumber[] - Values to plot, in order.
labelsstring[] - Optional label per bar, shown in the tooltip.
showValuesbooleanfalsePrint each value under its bar as well as on hover.
formatValue(value: number) => stringtoLocaleStringFormats the number in the tooltip and the value row.

Accessibility

  • Values are readable as text via showValues, not only on hover.
  • The tooltip anchors to the bar, so it never jitters with the pointer.
  • Heights are relative to the maximum, so any range renders sensibly.
  • Hover changes bar colour and shows a value, so it is not colour-only.

Dependencies

motionclsxtailwind-merge