Category Bar for React
A React category bar splits one bar into named bands and pins where a value sits, such as a credit score or an NPS. Pass data as readonly CategoryBarItem[]: the bands, start to end.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/category-bar.jsonCredit score
Poor 300–580. Fair 580–670. Good 670–740. Very good 740–800. Exceptional 800–850. Your score: 724, in Good
CategoryBarCategoryBarTabledefaultCategoryBarLabels- +1 more
Score with a marker
Bands on a 300–850 scale. Switch the month: the pin glides to the new score and its number rolls. Focus the bar and use the arrow keys to read each band.
Credit score
FICO® bands on the 300–850 scale
Poor 300–580. Fair 580–670. Good 670–740. Very good 740–800. Exceptional 800–850. Your score: 724, in Good
import { CategoryBar } from "@/components/sheenui/charts/category-bar";
import { type CategoryBarItem } from "@/components/sheenui/charts/category-bar/model";
import { CategoryBarTable } from "@/components/sheenui/charts/category-bar/parts";
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, CategoryBarTable, CategoryBar, type CategoryBarItem } from "@sheenui/theme";
const bands: CategoryBarItem[] = [
{ label: "Poor", value: 280, color: 8 },
{ label: "Fair", value: 90, color: 2 },
{ label: "Good", value: 70, color: 4 },
{ label: "Very good", value: 60, color: 3 },
{ label: "Exceptional", value: 50, color: 6 },
];
<ChartCard
title="Credit score"
table={<CategoryBarTable data={bands} start={300} marker={724} markerLabel="Your score" />}
>
<CategoryBar
data={bands}
start={300}
marker={724}
markerLabel="Your score"
showLegend
aria-label="Credit score bands, 300 to 850"
/>
</ChartCard>Files to copy
15 folders · 32 files · 4 packages
- From
theme/src/ components/charts/{category-bar.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}components/button/components/charts/category-bar/components/charts/chart-parts/components/charts/heatmap/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/spinner/components/status-icons/hooks/{use-controllable.ts, use-direction.ts, use-intersection.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}motion/{gate.ts, tokens.ts}lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/category-bar.jsonRegistry item: category-bar. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Budgets and scores
Custom formats, a scale that starts below zero, and the compact size. Long boundary values drop out before they could touch.
Checkout latency
p95 over the last hour
Fast 0 ms–200 ms. Acceptable 200 ms–500 ms. Slow 500 ms–1,000 ms. Critical 1,000 ms–1,500 ms. p95: 342 ms, in Acceptable
Net promoter score
Q3 survey, 1,284 replies
Needs work −100 – 0. Good 0–30. Great 30–70. Excellent 70–100. NPS: 46, in Great
import { CategoryBar } from "@/components/sheenui/charts/category-bar";
import { type CategoryBarItem } from "@/components/sheenui/charts/category-bar/model";
// Package build (after the first npm release, or a packed tarball): import { CategoryBar, type CategoryBarItem } from "@sheenui/theme";
const npsBands: CategoryBarItem[] = [
{ label: "Needs work", value: 100, color: 8 },
{ label: "Good", value: 30, color: 4 },
{ label: "Great", value: 40, color: 3 },
{ label: "Excellent", value: 30, color: 6 },
];
export function Example() {
return (
<>
<CategoryBar
data={[
{ label: "Fast", value: 200, color: 3 },
{ label: "Acceptable", value: 300, color: 4 },
{ label: "Slow", value: 500, color: 2 },
{ label: "Critical", value: 500, color: 8 },
]}
marker={342}
markerLabel="p95"
format={(n) => Math.round(n).toLocaleString("en") + " ms"}
aria-label="Checkout latency budget"
/>
<CategoryBar
data={npsBands}
start={-100}
marker={46}
markerLabel="NPS"
size="sm"
showLegend
aria-label="Net promoter score bands"
/>
</>
);
}Props
CategoryBarLabels keys and English defaults (11)
CategoryBarTable props
Keyboard
Accessibility
- The bar is one focusable figure with a role description of “chart”; its description is the keyboard hint, and its description lists every band and where the marker falls.
- Moving through the bands announces each span once through a polite live region; pointer hovers stay silent.
- Bands are named in the legend, the tooltip and the table: color is never the only cue. Boundary values thin out instead of overlapping.
- On touch screens the hit area grows to 44px without moving anything; forced colors outline every band and the pin.
- Reduced motion: bands, pin and number appear in place, with no slide or roll.
All exports on this page
CategoryBar— A single bar split into bands, with an optional marker: where a score, a reading or a forecast sits on a scale of named ranges (Tremor's CategoryBar).CategoryBarTable— Every band with its span and share of the scale, then where the marker falls.defaultCategoryBarLabels— The built-in English strings of CategoryBar; spread it into your own labels and change what you need.
When to use the category bar chart
- Use it as a credit score bar to place a score, risk rating or health reading on a scale of named bands such as Poor, Fair, Good and Excellent, with the marker showing where the person sits now. Use it as a segmented bar chart when one total splits into a few named bands, such as a score ranging from low to high.
- Use it as a compact forecast bar inside a table row or settings card: bands sized to real values, boundary numbers underneath, and one pin with a label and value bubble.
- Set start when the scale does not begin at zero, for example 300 for a credit score, and marker to a value outside the scale to see it pinned to an end with an arrow.
- Skip it when the segments are parts of a whole that must sum to something, where a Percent bar chart or Donut chart fits, or when you rank many items, where Bar list is the better tool.
- Pair it with ChartCard and CategoryBarTable for a text view, plus a Badge next to it to name the current band in words for readers who skip charts.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .