Category Bar
A single segmented bar that shows how a total splits into parts, with an optional marker.
Overview
A category bar divides one bar into segments sized by their share of the total. It is the compact choice for a part-to-whole breakdown inside a card or table: storage by file type, budget by category, survey answers, or a score placed on banded ranges with a marker. With more than five or six segments, or when values are close, a Bar List or Bar Chart is easier to compare.
Anatomy
CategoryBar reads a name and a value from each row and draws the segments in data order; each name is a config key for its label and color. Optional parts sit around the bar: showLabels prints the cumulative value at each boundary, dropping any that would collide; marker draws a tick at a value on the same scale; and showLegend lists the segments under the bar. The bar is drawn with DOM elements, so it stays crisp at any size.
Accessibility
The bar is an image whose generated accessible name lists every segment with its value and share, and the marker if there is one, for example "Video 38.4 GB (38.4%), Photos 21.7 GB (21.7%)". Pass ariaLabel to replace it. Segment tooltips are pointer-operated, so pair the bar with a legend or written figures when readers need exact values. Choose segment colors with enough contrast against each other and the page.
Installation
Usage
import { CategoryBar, type ChartConfig } from "honestui/charts";<CategoryBar
data={data}
config={chartConfig}
nameKey="type"
valueKey="gigabytes"
valueFormatter={(value) => `${value} GB`}
showLegend
/>Segments are proportional to the sum of all values. To show remaining capacity, add a row for it with a neutral color, as the "Available" segment does above.
Examples
Marker and labels
A marker places one value on the bar, such as a score on banded ranges. The marker uses the same scale as the summed values, so this example offsets the score by the scale's origin and adds it back in labelFormatter, which formats positions on the scale (boundary labels and the marker) separately from segment values.
Percentages
With percent, labels and tooltips show each share of the total, and the tooltip detail shows the raw value.
Loading State
Pass isLoading to draw a neutral bar with the same loading treatment as the other Honest UI charts.