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
| month | Desktop | Mobile |
|---|---|---|
| January | 342 | 245 |
| February | 476 | 189 |
| March | 291 | 312 |
| April | 418 | 156 |
| May | 385 | 278 |
| June | 452 | 221 |
| July | 267 | 334 |
| August | 493 | 198 |
| September | 356 | 287 |
| October | 431 | 176 |
| November | 309 | 352 |
| December | 468 | 215 |
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.
| month | Desktop | Mobile |
|---|---|---|
| January | 342 | 245 |
| February | 476 | 189 |
| March | 291 | 312 |
| April | 418 | 156 |
| May | 385 | 278 |
| June | 452 | 221 |
| July | 267 | 334 |
| August | 493 | 198 |
| September | 356 | 287 |
| October | 431 | 176 |
| November | 309 | 352 |
| December | 468 | 215 |
const { data, isLoading } = useSales()
<GlitterBarChart data={data ?? []} xKey="month" series={series} isLoading={isLoading} />Setup
Install with the shadcn CLI
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
Run in your terminal:
$npm install clsx tailwind-merge lucide-react - 2
Copy
lib/utils.tsfrom the Code tab. Skip if you already havecn(). - 3
Copy
styles/tokens.cssfrom the Code tab and import it in your global CSS after Tailwind:@import "./styles/tokens.css"; - 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
Import and render:
Exampleimport { 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:
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
| Prop | Type | Default | What it does |
|---|---|---|---|
data | T[] | — | One row per category. |
xKey | keyof T | — | The field that holds each category's label. |
series | GlitterSeries[] | — | The bars in each group, left to right. |
height | number | 260 | Height 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. |
duration | number | 1800 | Time until the last bar finishes, in milliseconds. |
dotSize | number | 3 | Size of each dot in pixels. |
gap | number | 1.5 | Space between dots in pixels. |
glitter | boolean | true | Dots twinkle, and now and then one sparkles white. |
glow | boolean | true | A soft glow around the lit dots. |
track | boolean | true | Faint empty dots above each bar. |
isLoading | boolean | false | Shows a shimmering skeleton instead of the bars. |
loadingBars | number | 12 | How many bars the skeleton has. |
grid | boolean | true | Dashed lines across the chart. |
yAxis | boolean | false | Value labels on the left. |
yTicks | number | 5 | How many steps the value axis has. The dashed grid lines and the y-axis labels both follow it. |
legend | boolean | true | Clickable series names above the chart. |
xFormatter | (value: string) => string | — | Changes how the category labels look. |
format | (value: number) => string | toLocaleString | Formats values in the tooltip and on the y axis. |
defaultSelected | string | null | null | A series to focus at the start. |
onSelectionChange | (key: string | null) => void | — | Runs when a legend item is clicked. |
GlitterSeries
| Field | Type | What it is |
|---|---|---|
key | string | The field in each row that holds this series' value. |
label | string? | Name in the legend and tooltip. Defaults to the key. |
color | string | Any 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