# Bar list

Source: https://ecosphere.dev/docs/charts/bar-list (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A ranked list of named values: a two-line label, the value, its share of the total and a bar scaled to the largest item.

`import { EcoBarList } from "vue-ecosphere"`

## Top 5 of 9, with share and Show all

The order is the ranking, so it is a real ol. The share column is of the whole month, including the rows not shown.

Vue (vue-ecosphere):

```vue
<section class="card" aria-labelledby="plT">
  <div class="card__head"><div>
    <h3 class="card-title" id="plT">Revenue by product line, May</h3>
    <p class="caption">Before tax. Shares are of all revenue in the month.</p>
  </div></div>
  <div class="card__body">
    <EcoBarList v-model:expanded="expanded" :items="lines" :limit="5" noun="product lines" />
  </div>
</section>
```

React (react-ecosphere):

```tsx
const [expanded, setExpanded] = useState(false);

<section className="card" aria-labelledby="plT">
  <div className="card__head"><div>
    <h3 className="card-title" id="plT">Revenue by product line, May</h3>
    <p className="caption">Before tax. Shares are of all revenue in the month.</p>
  </div></div>
  <div className="card__body">
    <EcoBarList expanded={expanded} onExpandedChange={setExpanded} items={lines} limit={5} noun="product lines" />
  </div>
</section>
```

## Each row a link

Link the name only, not the value or the bar.

Vue (vue-ecosphere):

```vue
<EcoBarList :items="[
  { name: 'North', href: '#north', detail: '14 stores · 21,960 orders', value: 2.1, display: '$2.10M', share: '43.6%' },
  …
]" />
```

React (react-ecosphere):

```tsx
<EcoBarList items={[
  { name: "North", href: "#north", detail: "14 stores · 21,960 orders", value: 2.1, display: "$2.10M", share: "43.6%" },
  …
]} />
```

## Two groups with a signed change, no share

Sign every value with a true minus and scale both groups to the largest absolute change.

Vue (vue-ecosphere):

```vue
<EcoBarList title="Increases" :items="ups" :show-share="false" :scale-max="182" />
<EcoBarList title="Decreases" :items="downs" :show-share="false" :scale-max="182" />
```

React (react-ecosphere):

```tsx
<EcoBarList title="Increases" items={ups} showShare={false} scaleMax={182} />
<EcoBarList title="Decreases" items={downs} showShare={false} scaleMax={182} />
```

## Empty

Say what is missing and for when.

Vue (vue-ecosphere):

```vue
<section class="card" aria-labelledby="chT">
  <div class="card__head"><div><h3 class="card-title" id="chT">Revenue by sales channel, May</h3></div></div>
  <div class="card__body">
    <EcoBarList :items="[]" empty-text="No sales recorded for this store in May." />
  </div>
</section>
```

React (react-ecosphere):

```tsx
<section className="card" aria-labelledby="chT">
  <div className="card__head"><div><h3 className="card-title" id="chT">Revenue by sales channel, May</h3></div></div>
  <div className="card__body">
    <EcoBarList items={[]} emptyText="No sales recorded for this store in May." />
  </div>
</section>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `BarListItem[]` | — | Rows in rank order: name, detail, value, display, share, href. |
| `title` | `string` | — | Group title (h4.barlist__t) for two related rankings. |
| `limit` | `number` | — | Show the top N and a “Show all” disclosure button. |
| `v-model:expanded` | `boolean` | false | Whether every row is shown. |
| `noun` | `string` | "items" | Footer caption: “Top 5 of 9 product lines”. |
| `total` | `number` | — | The whole the computed shares are of, including rows not shown. |
| `showShare` | `boolean` | true | Leave the share out where it means nothing, as with changes. |
| `scaleMax` | `number` | — | Scale bars to one value across groups (the largest absolute change). |
| `valueFormat` | `(v: number) => string` | — | Formats a value when the item has no display text. |
| `emptyText` | `string` | — | barlist__empty: what is missing and for when. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `BarListItem[]` | — | Rows in rank order: name, detail, value, display, share, href. |
| `title` | `string` | — | Group title (h4.barlist__t) for two related rankings. |
| `limit` | `number` | — | Show the top N and a “Show all” disclosure button. |
| `expanded / onExpandedChange` | `boolean` | false | Whether every row is shown. Leave both out, or pass defaultExpanded, and the list keeps its own state. |
| `noun` | `string` | "items" | Footer caption: “Top 5 of 9 product lines”. |
| `total` | `number` | — | The whole the computed shares are of, including rows not shown. |
| `showShare` | `boolean` | true | Leave the share out where it means nothing, as with changes. |
| `scaleMax` | `number` | — | Scale bars to one value across groups (the largest absolute change). |
| `valueFormat` | `(v: number) => string` | — | Formats a value when the item has no display text. |
| `emptyText` | `string` | — | barlist__empty: what is missing and for when. |
