# Statistics

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

The figures a dashboard leads with: an eyebrow, a value with its delta, a segmented bar and its legend — and KPI tiles.

`import { EcoStat, EcoKpi, EcoValueChange } from "vue-ecosphere"`

## Stat

Lead with the number, not a chart. Step through the periods: the delta follows the direction.

Vue (vue-ecosphere):

```vue
<EcoStat label="Requests closed" :value="18" delta="32%" trend="up">
  <template #actions>
    <div class="wknav">
      <button class="iconbtn iconbtn--sm" type="button" aria-label="Previous period" @click="prev">
        <i class="ri-arrow-left-s-line" aria-hidden="true"></i></button>
      <span class="rangebtn">This week</span>
      <button class="iconbtn iconbtn--sm" type="button" aria-label="Next period" :disabled="isLatest" @click="next">
        <i class="ri-arrow-right-s-line" aria-hidden="true"></i></button>
    </div>
  </template>
</EcoStat>
```

React (react-ecosphere):

```tsx
<EcoStat
  label="Requests closed"
  value={18}
  delta="32%"
  trend="up"
  actions={
    <div className="wknav">
      <button className="iconbtn iconbtn--sm" type="button" aria-label="Previous period" onClick={prev}>
        <i className="ri-arrow-left-s-line" aria-hidden="true"></i></button>
      <span className="rangebtn">This week</span>
      <button className="iconbtn iconbtn--sm" type="button" aria-label="Next period" disabled={isLatest} onClick={next}>
        <i className="ri-arrow-right-s-line" aria-hidden="true"></i></button>
    </div>
  }
/>
```

## Segbar and legend

The parts of one figure, coloured by the magnitude ramp.

Vue (vue-ecosphere):

```vue
<EcoStat :segments="[
  { label: 'Responded', value: 45 },
  { label: 'Awaiting review', value: 31 },
  { label: 'No response', value: 24 },
]" />
```

React (react-ecosphere):

```tsx
<EcoStat
  segments={[
    { label: "Responded", value: 45 },
    { label: "Awaiting review", value: 31 },
    { label: "No response", value: 24 },
  ]}
/>
```

## KPI grid

Icon, value, toned delta, helper. Returns going down is good: the tone follows the judgement.

Vue (vue-ecosphere):

```vue
<div class="kpis">
  <EcoKpi label="Revenue in May" icon="money-dollar-circle-line" value="$4.82M"
    delta="Up 6.1%" vs="vs April" judgement="good" hint="All product lines, before tax" />
  <EcoKpi label="Average order value" icon="shopping-bag-line" value="$86.40"
    delta="Down 4.5%" trend="down" vs="vs April" judgement="bad" hint="Across 55,790 orders · online and in store" />
  <EcoKpi label="Returns, last 12 months" icon="refresh-line" value="$1.21M"
    delta="Down 8.2%" trend="down" vs="vs the prior 12 months" judgement="good" hint="Refunds and exchanges" />
  <EcoKpi label="Units in stock" icon="box-3-line" value="18,420" delta="Up 2.0%" vs="vs April" hint="Six warehouses" />
</div>
```

React (react-ecosphere):

```tsx
<div className="kpis">
  <EcoKpi label="Revenue in May" icon="money-dollar-circle-line" value="$4.82M"
    delta="Up 6.1%" vs="vs April" judgement="good" hint="All product lines, before tax" />
  <EcoKpi label="Average order value" icon="shopping-bag-line" value="$86.40"
    delta="Down 4.5%" trend="down" vs="vs April" judgement="bad" hint="Across 55,790 orders · online and in store" />
  <EcoKpi label="Returns, last 12 months" icon="refresh-line" value="$1.21M"
    delta="Down 8.2%" trend="down" vs="vs the prior 12 months" judgement="good" hint="Refunds and exchanges" />
  <EcoKpi label="Units in stock" icon="box-3-line" value="18,420" delta="Up 2.0%" vs="vs April" hint="Six warehouses" />
</div>
```

## KPI states

Loading, unchanged, and nothing to compare — never “0%” for a comparison that does not exist.

Vue (vue-ecosphere):

```vue
<EcoKpi label="Revenue in June" icon="money-dollar-circle-line" loading />
<EcoKpi label="Active stores" icon="store-2-line" value="42" delta="Unchanged" trend="flat" vs="vs April" hint="Open at least one day in May" />
<EcoKpi label="Revenue, last 12 months" icon="line-chart-line" value="$52.6M" hint="No earlier 12 months stored to compare with" />
```

React (react-ecosphere):

```tsx
<EcoKpi label="Revenue in June" icon="money-dollar-circle-line" loading />
<EcoKpi label="Active stores" icon="store-2-line" value="42" delta="Unchanged" trend="flat" vs="vs April" hint="Open at least one day in May" />
<EcoKpi label="Revenue, last 12 months" icon="line-chart-line" value="$52.6M" hint="No earlier 12 months stored to compare with" />
```

## Value change

Old value struck through, the new one, a signed badge; a screen reader hears one sentence.

Vue (vue-ecosphere):

```vue
<EcoValueChange from="12.40" to="13.10" change="+5.6%" label="From 12.40 to 13.10, up 5.6%" />
<EcoValueChange from="9.80" to="9.49" change="−3.2%" label="From 9.80 to 9.49, down 3.2%" />
<EcoValueChange to="4.50" change="No change" label="4.50, unchanged" />
<EcoValueChange from="3.4 days" to="2.9 days" change="−14.7%" tone="success"
  label="Average delivery time from 3.4 to 2.9 days, down 14.7%, an improvement" />
```

React (react-ecosphere):

```tsx
<EcoValueChange from="12.40" to="13.10" change="+5.6%" label="From 12.40 to 13.10, up 5.6%" />
<EcoValueChange from="9.80" to="9.49" change="−3.2%" label="From 9.80 to 9.49, down 3.2%" />
<EcoValueChange to="4.50" change="No change" label="4.50, unchanged" />
<EcoValueChange from="3.4 days" to="2.9 days" change="−14.7%" tone="success"
  label="Average delivery time from 3.4 to 2.9 days, down 14.7%, an improvement" />
```

## Stat API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | — | Eyebrow over the figure. |
| `value` | `string \| number` | — | The figure, in --font-num with tabular digits. |
| `delta / trend` | `string / "up" \| "down"` | — / "up" | Delta with an arrow; down takes stat__delta--down. Say what it is measured against, or leave it off. |
| `segments` | `EcoStatSegment[]` | — | { label, value, color?, display? }: the segbar and its legend. Colours default to the --p5, --p2, --p0 ramp. |
| `#actions` | `—` | — | The period control beside the figure (wknav). |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | — | Eyebrow over the figure. |
| `value` | `string \| number` | — | The figure, in --font-num with tabular digits. |
| `delta / trend` | `string / "up" \| "down"` | — / "up" | Delta with an arrow; down takes stat__delta--down. Say what it is measured against, or leave it off. |
| `segments` | `EcoStatSegment[]` | — | { label, value, color?, display? }: the segbar and its legend. Colours default to the --p5, --p2, --p0 ramp. |
| `actions` | `ReactNode` | — | The period control beside the figure (wknav). |

## Kpi and ValueChange API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label / icon` | `string` | — | Tile name and its decorative RemixIcon. |
| `value` | `string \| number` | — | Formatted before it reaches the tile; it does not abbreviate. |
| `delta / trend / vs` | `string / "up" \| "down" \| "flat" / string` | — | Arrow and words (“Up 6.1%”) and what it is measured against. |
| `judgement` | `"good" \| "bad"` | — | Tone only where direction is a judgement; it follows the judgement, not the arrow. |
| `hint` | `string` | — | Helper at the foot of the tile; aligns across a kpis row. |
| `loading` | `boolean` | false | Skeletons with aria-busy; label and icon stay. |
| `level` | `2 \| 3 \| 4` | — | Make the label a heading. |
| `EcoValueChange` | `component` | — | from, to, change, tone (default neutral), label (the sr sentence). |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label / icon` | `string` | — | Tile name and its decorative RemixIcon. |
| `value` | `string \| number` | — | Formatted before it reaches the tile; it does not abbreviate. |
| `delta / trend / vs` | `string / "up" \| "down" \| "flat" / string` | — | Arrow and words (“Up 6.1%”) and what it is measured against. |
| `judgement` | `"good" \| "bad"` | — | Tone only where direction is a judgement; it follows the judgement, not the arrow. |
| `hint` | `string` | — | Helper at the foot of the tile; aligns across a kpis row. |
| `loading` | `boolean` | false | Skeletons with aria-busy; label and icon stay. |
| `level` | `2 \| 3 \| 4` | — | Make the label a heading. |
| `EcoValueChange` | `component` | — | from, to, change, tone (default neutral), label (the sr sentence). |
