Bar Chart

A grouped bar chart made of glowing dots. Bars grow up one after another with a white-hot tip, then keep twinkling. Hover a month for a tooltip, or click a legend item to focus one series.

Preview

Loading State

Pass isLoading to show a shimmering skeleton while your data loads. When it turns false, the real bars grow in with the usual animation.

Example
const { data, isLoading } = useSales()

<GlitterBarChart data={data ?? []} xKey="month" series={series} isLoading={isLoading} />

Setup

Install with the shadcn CLI

$npx shadcn@latest add https://kinetikui.singhgourav.site/r/glitter-bar-chart.json

One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.

Or install manually

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/utils.ts from the Code tab. Skip if you already have cn().

  3. 3

    Copy styles/tokens.css from the Code tab and import it in your global CSS after Tailwind: @import "./styles/tokens.css";

  4. 4

    Create a components/ui/glitter-bar-chart/ folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest.

  5. 5

    Import and render:

    Example
    import { GlitterBarChart } from "@/components/ui/glitter-bar-chart"
    
    <GlitterBarChart data={data} xKey="month" series={[{ key: "desktop", color: "#10b981" }]} />

Usage

Pass your rows as data, say which field holds the category with xKey, and add one entry to series for each bar in a group:

Example
import { GlitterBarChart } from "@/components/ui/glitter-bar-chart"

const data = [
  { month: "January", desktop: 342, mobile: 245 },
  { month: "February", desktop: 476, mobile: 189 },
  // …
]

<GlitterBarChart
  data={data}
  xKey="month"
  xFormatter={(m) => m.slice(0, 3)}
  series={[
    { key: "desktop", label: "Desktop", color: "#10b981" },
    { key: "mobile", label: "Mobile", color: "#f43f5e" },
  ]}
/>

The top of the chart is rounded up to a tidy number, so the tallest bar rarely touches the top. The hover card glides after your pointer instead of snapping to it.

To play the animation again, change the chart's key.

Props

PropTypeDefaultWhat it does
dataT[]—One row per category.
xKeykeyof T—The field that holds each category's label.
seriesGlitterSeries[]—The bars in each group, left to right.
heightnumber260Height of the bars area in pixels.
animationType"left-to-right" | "right-to-left" | "center-out" | "edges-in" | "none""left-to-right"The order the bars grow in.
durationnumber1800Time until the last bar finishes, in milliseconds.
dotSizenumber3Size of each dot in pixels.
gapnumber1.5Space between dots in pixels.
glitterbooleantrueDots twinkle, and now and then one sparkles white.
glowbooleantrueA soft glow around the lit dots.
trackbooleantrueFaint empty dots above each bar.
isLoadingbooleanfalseShows a shimmering skeleton instead of the bars.
loadingBarsnumber12How many bars the skeleton has.
gridbooleantrueDashed lines across the chart.
yAxisbooleanfalseValue labels on the left.
yTicksnumber5How many steps the value axis has. The dashed grid lines and the y-axis labels both follow it.
legendbooleantrueClickable series names above the chart.
xFormatter(value: string) => string—Changes how the category labels look.
format(value: number) => stringtoLocaleStringFormats values in the tooltip and on the y axis.
defaultSelectedstring | nullnullA series to focus at the start.
onSelectionChange(key: string | null) => void—Runs when a legend item is clicked.

GlitterSeries

FieldTypeWhat it is
keystringThe field in each row that holds this series' value.
labelstring?Name in the legend and tooltip. Defaults to the key.
colorstringAny CSS colour: hex, rgb(), hsl() or oklch().

Accessibility

  • The chart's numbers are also in a table that only screen readers see
  • Legend items are buttons that say whether they are selected (aria-pressed)
  • While loading, the chart is marked busy (aria-busy) and a “Loading” status is announced
  • With reduced motion turned on, the bars show at full height straight away and the dots don't twinkle