# Diverging bar chart

Source: https://ecosphere.dev/docs/charts/diverging-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.

Two opposed amounts per period, growing up and down from one strong zero line on one shared scale.

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

## Over and under, by month

Over in s1, under in s6: one blue and one neutral, never red and green. A tiny amount still draws a 3px stub; the exact figure is in the tooltip.

Vue (vue-ecosphere):

```vue
<EcoDivergingBarChart
  :data="[
    { label: 'May', year: 2025, over: 4200, under: 1800, title: 'May 2025' },
    { label: 'Jun', year: 2025, over: 0, under: 7600, title: 'June 2025' },
    …
    { label: 'Oct', year: 2026, over: 9800, under: 2600, title: 'October 2026' },
  ]"
  over-label="Over budget"
  under-label="Under budget"
  :value-format="(v) => '$' + v.toLocaleString('en-US')"
  :tick-format="(v) => '$' + v / 1000 + 'k'"
  title="Spend against budget"
  subtitle="By month, May 2025 – October 2026"
/>
```

React (react-ecosphere):

```tsx
<EcoDivergingBarChart
  data={[
    { label: "May", year: 2025, over: 4200, under: 1800, title: "May 2025" },
    { label: "Jun", year: 2025, over: 0, under: 7600, title: "June 2025" },
    …
    { label: "Oct", year: 2026, over: 9800, under: 2600, title: "October 2026" },
  ]}
  overLabel="Over budget"
  underLabel="Under budget"
  valueFormat={(v) => "$" + v.toLocaleString("en-US")}
  tickFormat={(v) => "$" + v / 1000 + "k"}
  title="Spend against budget"
  subtitle="By month, May 2025 – October 2026"
/>
```

## Narrow and empty

At 360px every third month is labelled and the legend wraps.

Vue (vue-ecosphere):

```vue
<div style="width:360px">
  <EcoDivergingBarChart :data="data" :height="216" … />
</div>
```

React (react-ecosphere):

```tsx
<div style={{ width: 360 }}>
  <EcoDivergingBarChart data={data} height={216} … />
</div>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `DivergingDatum[]` | — | Per period: label, both amounts as positive numbers, the year and a long title. |
| `overLabel / underLabel` | `string` | "Over budget" / "Under budget" | Words for each side, used in the legend, the tooltip and every hit label. |
| `valueFormat` | `(v: number) => string` | — | Full figures (“$15,800”). |
| `tickFormat` | `(v: number) => string` | — | Unsigned tick figures; the chart adds + and a true minus. |
| `height / width` | `number` | 240 / measured | viewBox size; labels thin from the measured width, counted back from the latest. |
| `title / subtitle / caption / ariaLabel` | `string` | — | Head, closing chart__sub and the svg label. Slot actions holds the Chart \| Table toggle. |
| `emptyTitle / emptyText` | `string` | — | chart__empty when there is no data. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `data` | `DivergingDatum[]` | — | Per period: label, both amounts as positive numbers, the year and a long title. |
| `overLabel / underLabel` | `string` | "Over budget" / "Under budget" | Words for each side, used in the legend, the tooltip and every hit label. |
| `valueFormat` | `(v: number) => string` | — | Full figures (“$15,800”). |
| `tickFormat` | `(v: number) => string` | — | Unsigned tick figures; the chart adds + and a true minus. |
| `height / width` | `number` | 240 / measured | viewBox size; labels thin from the measured width, counted back from the latest. |
| `title / subtitle / caption / ariaLabel` | `string` | — | Head, closing chart__sub and the svg label. The actions prop (ReactNode) holds the Chart \| Table toggle. |
| `emptyTitle / emptyText` | `string` | — | chart__empty when there is no data. |
