# Bar List

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

Source: https://www.honestui.com/docs/charts/bar-list/static

### Basic Bar List

```tsx
"use client";

import { BarList, type ChartConfig } from "honestui/charts";

// Scenario: Top pages by visitors
const data = [
  { page: "/", visitors: 8420 },
  { page: "/pricing", visitors: 3912 },
  { page: "/docs/getting-started", visitors: 3104 },
  { page: "/blog/launch-week", visitors: 2287 },
  { page: "/changelog", visitors: 1460 },
  { page: "/careers", visitors: 642 },
];

const chartConfig = {
  visitors: {
    label: "Visitors",
    colors: {
      light: ["#2563eb"],
      dark: ["#3b82f6"],
    },
  },
} satisfies ChartConfig;

export function ExampleBarList() {
  return (
    <BarList
      data={data}
      config={chartConfig}
      nameKey="page"
      valueKey="visitors"
      nameLabel="Page"
      valueLabel="Visitors"
      className="w-full max-w-md"
    />
  );
}

```

## Overview [#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](/docs/charts/bar-chart/static) when categories need to be compared across several series or over time.

## Anatomy [#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 [#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 [#installation]

<CommandBlock commands="[&#x22;honestui&#x22;]" />

## Usage [#usage]

```tsx
import { BarList, type ChartConfig } from "honestui/charts";
```

```tsx
<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 [#examples]

### Track variant [#track-variant]

### variant='track'

```tsx
"use client";

import { BarList, type ChartConfig } from "honestui/charts";
import { Laptop, Monitor, Smartphone, Tablet } from "honestui/icons";

// Scenario: Sessions by device, each row with its own color and icon
const data = [
  { device: "desktop", sessions: 0.512 },
  { device: "mobile", sessions: 0.384 },
  { device: "laptop", sessions: 0.071 },
  { device: "tablet", sessions: 0.033 },
];

const chartConfig = {
  sessions: { label: "Sessions" },
  desktop: {
    label: "Desktop",
    icon: Monitor,
    colors: { light: ["#2563eb"], dark: ["#3b82f6"] },
  },
  mobile: {
    label: "Mobile",
    icon: Smartphone,
    colors: { light: ["#059669"], dark: ["#10b981"] },
  },
  laptop: {
    label: "Laptop",
    icon: Laptop,
    colors: { light: ["#d97706"], dark: ["#f59e0b"] },
  },
  tablet: {
    label: "Tablet",
    icon: Tablet,
    colors: { light: ["#7c3aed"], dark: ["#8b5cf6"] },
  },
} satisfies ChartConfig;

export function ExampleBarListTrack() {
  return (
    <BarList
      data={data}
      config={chartConfig}
      nameKey="device"
      valueKey="sessions"
      variant="track"
      max={1}
      valueFormatter={(value) => `${(value * 100).toFixed(1)}%`}
      className="w-full max-w-sm"
    />
  );
}

```

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 [#selectable-rows]

### onValueChange

```tsx
"use client";

import { useState } from "react";
import { BarList, type ChartConfig } from "honestui/charts";

// Scenario: Filter a dashboard by referrer
const data = [
  { source: "Google", visits: 4820 },
  { source: "Direct", visits: 3310 },
  { source: "GitHub", visits: 1984 },
  { source: "Newsletter", visits: 1236 },
  { source: "Hacker News", visits: 918 },
  { source: "LinkedIn", visits: 402 },
];

const chartConfig = {
  visits: {
    label: "Visits",
    colors: {
      light: ["#0d9488"],
      dark: ["#14b8a6"],
    },
  },
} satisfies ChartConfig;

export function ExampleBarListSelectable() {
  const [selected, setSelected] = useState<string | null>("GitHub");
  const total = data.reduce((sum, row) => sum + row.visits, 0);
  const shown = selected ? (data.find((row) => row.source === selected)?.visits ?? 0) : total;

  return (
    <div className="grid w-full max-w-md gap-3 text-xs">
      <div className="flex items-baseline justify-between">
        <span className="text-muted-foreground">{selected ? `Visits from ${selected}` : "All visits"}</span>
        <span className="text-foreground font-mono text-base font-medium tabular-nums">
          {shown.toLocaleString()}
        </span>
      </div>
      <BarList
        data={data}
        config={chartConfig}
        nameKey="source"
        valueKey="visits"
        selectedName={selected}
        onValueChange={(item) => setSelected((current) => (current === item.name ? null : item.name))}
        ariaLabel="Visits by referrer. Choose a referrer to filter."
      />
    </div>
  );
}

```

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 [#loading-state]

### isLoading='true'

```tsx
"use client";

import { BarList, type ChartConfig } from "honestui/charts";

const chartConfig = {
  visitors: {
    label: "Visitors",
    colors: {
      light: ["#2563eb"],
      dark: ["#3b82f6"],
    },
  },
} satisfies ChartConfig;

export function ExampleBarListLoading() {
  return (
    <BarList
      data={[]}
      config={chartConfig}
      nameKey="visitors"
      valueKey="visitors"
      nameLabel="Page"
      valueLabel="Visitors"
      isLoading
      className="w-full max-w-md"
    />
  );
}

```

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

## API Reference [#api-reference]

<ApiHeading>
  BarList
</ApiHeading>


  ### `data`

type: `TData[]`

One row per bar.

  ### `config`

type: `ChartConfig`

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

  ### `nameKey`

type: `keyof TData & string`

The row label.

  ### `valueKey`

type: `keyof TData & string`

The numeric value that sizes the bar.

  ### `hrefKey`

type: `keyof TData & string`

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

  ### `variant`

type: `&#x22;tinted&#x22; | &#x22;track&#x22;` · default: `&#x22;tinted&#x22;`

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

  ### `sortOrder`

type: `&#x22;descending&#x22; | &#x22;ascending&#x22; | &#x22;none&#x22;` · default: `&#x22;descending&#x22;`

Row order. `none` keeps the data order.

  ### `max`

type: `number`

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

  ### `limit`

type: `number`

Show at most this many rows after sorting.

  ### `valueFormatter`



string">
    Formats each value.

  ### `nameLabel`

type: `ReactNode`

Heading above the names.

  ### `valueLabel`

type: `ReactNode`

Heading above the values.

  ### `selectedName`

type: `string | null` · default: `null`

The selected row. Other rows are dimmed.

  ### `onValueChange`



) => void">
    Makes rows buttons and reports the chosen row's name, value, datum, and index.

  ### `animation`

type: `boolean` · default: `true`

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

  ### `isLoading`

type: `boolean` · default: `false`

Draws placeholder rows and a loading label.

  ### `loadingRows`

type: `number` · default: `5`

Number of placeholder rows.

  ### `ariaLabel`

type: `string`

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

  ### `className`

type: `string`

Classes for the container.
