Skip to documentation content

Bar List

A ranked list of labeled values with proportional bars, for top pages, referrers, and breakdowns.

Basic Bar List

Overview

A bar list ranks categories by value and draws a bar behind each label, so long names stay readable where a horizontal bar chart would truncate them. Use it for "top N" panels: pages, referrers, countries, devices, or error types. Prefer a Bar Chart when categories need to be compared across several series or over time.

Anatomy

BarList reads nameKey and valueKey from each row, sorts the rows, and scales every bar to the largest value or to max. Each row is a label, an optional icon, a bar, and a value. Two variants are available: tinted puts the label on a light wash of the bar color, and track puts a thin bar on a muted track under the label. The list is drawn with DOM elements rather than a canvas, so labels and values are real text.

Accessibility

The rows render as a list with real text, so screen readers read each name and value in order. Bars are decorative and hidden from assistive technology. Pass ariaLabel to name the list. With onValueChange, rows become buttons that report aria-pressed while a selectedName is set, and rows with an hrefKey value become links. Selection dims the other rows, so keep the selected value written out nearby as well.

Installation

npm install honestui

Usage

import { BarList, type ChartConfig } from "honestui/charts";
<BarList
  data={data}
  config={chartConfig}
  nameKey="page"
  valueKey="visitors"
  nameLabel="Page"
  valueLabel="Visitors"
/>

The config entry for valueKey sets the bar color. A row whose name is also a config key takes that entry's label, icon, and colors instead, which gives each category its own color.

Examples

Track variant

variant='track'

Track rows suit shares of a whole: set max={1} so every bar is measured against the full width rather than the largest row. Each device here has its own config entry with an icon and color.

Selectable rows

onValueChange

Use onValueChange with selectedName to filter the rest of a dashboard by a row. Choosing the selected row again clears the filter in this example.

Loading State

isLoading='true'

Pass isLoading to draw neutral placeholder rows with the same loading treatment as the other Honest UI charts.

API Reference

BarList
PropTypeDefaultDescription
data*TData[]–

One row per bar.

config*ChartConfig–

Colors for valueKey, plus optional per-row entries keyed by name.

nameKey*keyof TData & string–

The row label.

valueKey*keyof TData & string–

The numeric value that sizes the bar.

hrefKeykeyof TData & string–

A link for each row. Rows with a value render as anchors.

varianttinted|track"tinted"

A label on a tinted bar, or a thin bar under the label.

sortOrderdescending|ascending|none"descending"

Row order. none keeps the data order.

maxnumber–

The value of a full-width bar. Defaults to the largest value.

limitnumber–

Show at most this many rows after sorting.

valueFormatter(value: number) => string–

Formats each value.

nameLabelReactNode–

Heading above the names.

valueLabelReactNode–

Heading above the values.

selectedNamestring | nullnull

The selected row. Other rows are dimmed.

onValueChange(item: BarListItem<TData>) => void–

Makes rows buttons and reports the chosen row's name, value, datum, and index.

animationbooleantrue

Grows the bars in on mount. Reduced-motion preferences disable it.

isLoadingbooleanfalse

Draws placeholder rows and a loading label.

loadingRowsnumber5

Number of placeholder rows.

ariaLabelstring–

Accessible name for the list. Defaults to the value label and nameKey.

classNamestring–

Classes for the container.