# Bar chart

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

Magnitude compared across periods or categories: flat columns from zero, a small radius at the data end only, a light baseline.

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

## Columns

Every cap carries its value, so the chart needs no y-axis and no gridlines. Hover or focus a column for the change on the month before.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  :labels="['Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct']"
  :titles="titles"
  :data="[38, 44, 41, 52, 58, 66, 61, 71]"
  unit="requests closed"
  aria-label="Requests closed by month, March to October 2026"
>
  <template #head>
    <div class="card__head">
      <div>
        <p class="eyebrow">Requests closed</p>
        <div class="stat__value"><span class="stat__n">71</span><span class="stat__delta"><i class="ri-arrow-up-line" aria-hidden="true"></i>16%</span></div>
      </div>
    </div>
  </template>
</EcoBarChart>
```

React (react-ecosphere):

```tsx
<EcoBarChart
  labels={["Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct"]}
  titles={titles}
  data={[38, 44, 41, 52, 58, 66, 61, 71]}
  unit="requests closed"
  ariaLabel="Requests closed by month, March to October 2026"
  head={
    <div className="card__head">
      <div>
        <p className="eyebrow">Requests closed</p>
        <div className="stat__value"><span className="stat__n">71</span><span className="stat__delta"><i className="ri-arrow-up-line" aria-hidden="true"></i>16%</span></div>
      </div>
    </div>
  }
/>
```

## Against last period

The dark line across each column is last year’s figure. The dashed gridlines carry the scale, so the caps stay unlabelled.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  form="ghost"
  :labels="months"
  :titles="titles"
  :data="[38, 44, 41, 52, 58, 66, 61, 71]"
  :ghost="[31, 35, 44, 39, 47, 52, 58, 60]"
  name="This year"
  ghost-name="Last year"
  unit="closed"
  title="Closed, against last year"
/>
```

React (react-ecosphere):

```tsx
<EcoBarChart
  form="ghost"
  labels={months}
  titles={titles}
  data={[38, 44, 41, 52, 58, 66, 61, 71]}
  ghost={[31, 35, 44, 39, 47, 52, 58, 60]}
  name="This year"
  ghostName="Last year"
  unit="closed"
  title="Closed, against last year"
/>
```

## Stacked

Parts of a whole over a few periods, separated by a 2px gap; only the top segment is rounded. The total on each cap, the latest parts in the legend.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  :labels="months"
  :titles="titles"
  :series="[
    { name: 'Replied', values: [21, 25, 23, 30, 34, 39, 36, 42] },
    { name: 'Awaiting review', values: [12, 13, 13, 16, 17, 19, 18, 21] },
    { name: 'Blocked', values: [5, 6, 5, 6, 7, 8, 7, 8] },
  ]"
  unit="requests"
  title="Requests by outcome"
/>
```

React (react-ecosphere):

```tsx
<EcoBarChart
  labels={months}
  titles={titles}
  series={[
    { name: "Replied", values: [21, 25, 23, 30, 34, 39, 36, 42] },
    { name: "Awaiting review", values: [12, 13, 13, 16, 17, 19, 18, 21] },
    { name: "Blocked", values: [5, 6, 5, 6, 7, 8, 7, 8] },
  ]}
  unit="requests"
  title="Requests by outcome"
/>
```

## Horizontal

The form for long category names: nothing is rotated.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  form="horizontal"
  :labels="['Site reliability', 'Platform services', 'Security review', 'Analytics', 'Finance operations', 'Customer support']"
  :data="[31, 27, 22, 19, 12, 8]"
  unit="open"
  title="Open requests by team"
/>
```

React (react-ecosphere):

```tsx
<EcoBarChart
  form="horizontal"
  labels={["Site reliability", "Platform services", "Security review", "Analytics", "Finance operations", "Customer support"]}
  data={[31, 27, 22, 19, 12, 8]}
  unit="open"
  title="Open requests by team"
/>
```

## Emphasis and a target

October in accent, the other months in s-rest, and the target as a hairline. Only the month the chart is about carries its value.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  form="emphasis"
  :labels="months"
  :titles="titles"
  :data="[38, 44, 41, 52, 58, 66, 61, 71]"
  :target="60"
  unit="closed"
  aria-label="Requests closed by month, October highlighted, against a target of 60"
/>
```

React (react-ecosphere):

```tsx
<EcoBarChart
  form="emphasis"
  labels={months}
  titles={titles}
  data={[38, 44, 41, 52, 58, 66, 61, 71]}
  target={60}
  unit="closed"
  ariaLabel="Requests closed by month, October highlighted, against a target of 60"
/>
```

## Stacked over time, interactive

A year of periods keeps a y-axis and prints only the latest total. Focus a column: the others dim and the ChartTooltip lists every family, top segment first. Chart | Table shows the same figures as rows.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  :labels="['Nov', 'Dec', 'Jan', …, 'Oct']"
  :titles="['November 2025', …, 'October 2026']"
  :series="revenue"
  :value-format="(v) => '$' + v.toLocaleString('en-US')"
  :cap-format="(v) => '$' + (v / 1000).toFixed(1) + 'k'"
  :height="270"
  title="Revenue by product family"
  subtitle="Before tax, November 2025 – October 2026"
>
  <template #actions>
    <div class="seg seg--tight" role="group" aria-label="Show as">
      <button class="on" type="button" aria-pressed="true">Chart</button>
      <button type="button" aria-pressed="false">Table</button>
    </div>
  </template>
</EcoBarChart>
```

React (react-ecosphere):

```tsx
const [view, setView] = useState<"chart" | "table">("chart");

<EcoBarChart
  labels={["Nov", "Dec", "Jan", …, "Oct"]}
  titles={["November 2025", …, "October 2026"]}
  series={revenue}
  valueFormat={(v) => "$" + v.toLocaleString("en-US")}
  capFormat={(v) => "$" + (v / 1000).toFixed(1) + "k"}
  height={270}
  title="Revenue by product family"
  subtitle="Before tax, November 2025 – October 2026"
  actions={
    <div className="seg seg--tight" role="group" aria-label="Show as">
      <button className="on" type="button" aria-pressed="true">Chart</button>
      <button type="button" aria-pressed="false" onClick={() => setView("table")}>Table</button>
    </div>
  }
/>
```

## Narrow and empty

At 360px the bands narrow, bars keep 60% of them and labels thin to every other month. With no data the figure is replaced at the chart's height.

Vue (vue-ecosphere):

```vue
<EcoBarChart
  :labels="[]"
  :data="[]"
  title="Revenue by product family"
  subtitle="No data"
  empty-title="No revenue recorded yet"
  empty-text="Columns appear after the first month closes."
/>
```

React (react-ecosphere):

```tsx
<EcoBarChart
  labels={[]}
  data={[]}
  title="Revenue by product family"
  subtitle="No data"
  emptyTitle="No revenue recorded yet"
  emptyText="Columns appear after the first month closes."
/>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `labels` | `string[]` | — | Period or category labels on the axis. |
| `data` | `(number \| null)[]` | — | One series. Bars always grow from zero; null is a gap, never a zero. |
| `series` | `ChartSeries[]` | — | Stacked series, bottom segment first (largest at the bottom), in s1, s2, s3. |
| `form` | `"columns" \| "ghost" \| "stacked" \| "horizontal" \| "emphasis"` | "columns" | Each form answers a different question. Defaults to stacked when series is given. |
| `ghost` | `(number \| null)[]` | — | Last period's values: a ghost line 6 units wider than the bar on each side. |
| `name / ghostName` | `string` | "This year" / "Last year" | Legend names for the ghost form. |
| `current` | `number \| string` | latest | Highlighted label (xl on) and, in the emphasis form, the one bar in accent. |
| `target / targetLabel` | `number / string` | — | A target hairline with its label; the tooltip gives the distance from it. |
| `titles` | `string[]` | — | Long period names for the tooltip and hit labels (“October 2026”). |
| `unit` | `string` | — | Words after a figure: “requests closed”. |
| `valueFormat / capFormat / tickFormat` | `(v: number) => string` | — | Full figures; cap labels and legend values; y ticks. |
| `axis` | `boolean` | ghost, or stacked past 8 | A y-axis with nice ticks (1, 2, 2.5 or 5 × 10ⁿ, about four steps). Caps or axis, never both. |
| `height / width` | `number` | 234 / measured | viewBox height; the width follows the frame (ResizeObserver) unless fixed. |
| `title / subtitle / caption` | `string` | — | chart__head and a closing chart__sub. Slots head, actions and footer override them. |
| `ariaLabel` | `string` | — | Label of the svg group. Each band's hit area has its own complete label. |
| `emptyTitle / emptyText` | `string` | — | chart__empty at the chart's height when there is no data. |
| `tooltip / pointLabel` | `(i: number) => …` | — | Override the ChartTooltip card or the hit label for a band. |
| `@active-change` | `(i: number \| null)` | — | The band under the pointer or focus. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `labels` | `string[]` | — | Period or category labels on the axis. |
| `data` | `(number \| null)[]` | — | One series. Bars always grow from zero; null is a gap, never a zero. |
| `series` | `ChartSeries[]` | — | Stacked series, bottom segment first (largest at the bottom), in s1, s2, s3. |
| `form` | `"columns" \| "ghost" \| "stacked" \| "horizontal" \| "emphasis"` | "columns" | Each form answers a different question. Defaults to stacked when series is given. |
| `ghost` | `(number \| null)[]` | — | Last period's values: a ghost line 6 units wider than the bar on each side. |
| `name / ghostName` | `string` | "This year" / "Last year" | Legend names for the ghost form. |
| `current` | `number \| string` | latest | Highlighted label (xl on) and, in the emphasis form, the one bar in accent. |
| `target / targetLabel` | `number / string` | — | A target hairline with its label; the tooltip gives the distance from it. |
| `titles` | `string[]` | — | Long period names for the tooltip and hit labels (“October 2026”). |
| `unit` | `string` | — | Words after a figure: “requests closed”. |
| `valueFormat / capFormat / tickFormat` | `(v: number) => string` | — | Full figures; cap labels and legend values; y ticks. |
| `axis` | `boolean` | ghost, or stacked past 8 | A y-axis with nice ticks (1, 2, 2.5 or 5 × 10ⁿ, about four steps). Caps or axis, never both. |
| `height / width` | `number` | 234 / measured | viewBox height; the width follows the frame (ResizeObserver) unless fixed. |
| `title / subtitle / caption` | `string` | — | chart__head and a closing chart__sub. The head, actions and footer props (ReactNode) override them. |
| `ariaLabel` | `string` | — | Label of the svg group. Each band's hit area has its own complete label. |
| `emptyTitle / emptyText` | `string` | — | chart__empty at the chart's height when there is no data. |
| `tooltip / pointLabel` | `(i: number) => …` | — | Override the ChartTooltip card or the hit label for a band. |
| `onActiveChange` | `(i: number \| null)` | — | The band under the pointer or focus. |
