# Ranking and change

> Slope, bump and range charts for who moved and by how much, as copyable recipes.

Recipes for the FT Visual Vocabulary "ranking" family: slope charts, bump charts, and range (dumbbell/arrow) charts. All three answer the same editorial question, "who moved, and by how much?", with different emphasis.

Slope and bump are not separate chart types. They are `mark: "line"` plus a handful of public spec fields, documented here as copy-paste recipes. Range is its own mark (`mark: "range"`).

All specs work with any framework. Swap the import to match yours:

```tsx
// React
import { Chart } from "@opendata-ai/openchart-react";
<Chart spec={spec} />

// Vue
import { Chart } from "@opendata-ai/openchart-vue";
<Chart :spec="spec" />

// Svelte
import { Chart } from "@opendata-ai/openchart-svelte";
<Chart {spec} />

// Vanilla JS
import { createChart } from "@opendata-ai/openchart-vanilla";
createChart(container, spec);
```

---

## Slope

Two points in time, one line per series. The strongest form for "before vs after": every crossing line is a rank change, every steep line is a big move. Values live on the labels, so the y axis and gridlines go away entirely.

```json demo title="US electricity generation by source" source="US Energy Information Administration, Electric Power Monthly" height=460
{
  "mark": "line",
  "data": [
    { "year": "2010", "source": "Coal", "share": 44.8 },
    { "year": "2024", "source": "Coal", "share": 15 },
    { "year": "2010", "source": "Natural gas", "share": 23.9 },
    { "year": "2024", "source": "Natural gas", "share": 43.2 },
    { "year": "2010", "source": "Nuclear", "share": 19.6 },
    { "year": "2024", "source": "Nuclear", "share": 18.2 },
    { "year": "2010", "source": "Wind", "share": 2.3 },
    { "year": "2024", "source": "Wind", "share": 10.3 },
    { "year": "2010", "source": "Hydro", "share": 6.3 },
    { "year": "2024", "source": "Hydro", "share": 5.6 },
    { "year": "2010", "source": "Solar", "share": 0.1 },
    { "year": "2024", "source": "Solar", "share": 6.9 }
  ],
  "encoding": {
    "x": { "field": "year", "type": "ordinal" },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": false,
      "scale": { "zero": false }
    },
    "color": { "field": "source", "type": "nominal" }
  },
  "endpointLabels": { "ends": "both", "content": "label value", "format": ".1f" },
  "legend": { "show": false },
  "chrome": {
    "title": "Natural gas passed coal as the largest US electricity source between 2010 and 2024",
    "subtitle": "Share of US electricity generation by source, %, 2010 vs 2024"
  }
}
```

The rows are the source table's 2010 and 2024 columns, reshaped to one row per source and year.

What each field does:

- `endpointLabels.ends: 'both'` puts a label column at both edges (plain endpoint labels are trailing-edge only).
- `endpointLabels.content: 'label value'` joins the series name and its formatted value on one line ("Coal 44.8"). The classic FT look, name plus value on the left and value alone on the right, is `content: { leading: 'label value', trailing: 'value' }`.
- `axis: false` on y removes the axis and its gridlines. The labels carry the values, so an axis would be redundant ink.
- `scale: { zero: false }` lets the two rails span the data range instead of anchoring at zero, which is what makes the slopes readable.
- `legend: { show: false }` because the labels already identify every series.

Because the spec sets `endpointLabels` explicitly, the label columns survive the compact (under 400px) breakpoint, where auto endpoint labels would normally hand off to a legend. A slope without its labels is unreadable, so explicit opt-in wins.

---

## Bump

Rank over time. The y axis is the finishing position, reversed so 1st sits at the top, with ordinal tick labels ("1st, 2nd, 3rd"). Point markers anchor each step; monotone interpolation keeps the lines readable through crossings. Ties are fine: two series with the same rank share the same row.

```ts
const spec = {
  mark: { type: 'line', interpolate: 'monotone', point: true },
  data: [
    { season: '2019', team: 'Mercedes', position: 1 },
    { season: '2020', team: 'Mercedes', position: 1 },
    { season: '2021', team: 'Mercedes', position: 1 },
    { season: '2022', team: 'Mercedes', position: 3 },
    { season: '2023', team: 'Mercedes', position: 2 },
    { season: '2024', team: 'Mercedes', position: 4 },
    { season: '2019', team: 'Red Bull', position: 3 },
    { season: '2020', team: 'Red Bull', position: 2 },
    { season: '2021', team: 'Red Bull', position: 2 },
    { season: '2022', team: 'Red Bull', position: 1 },
    { season: '2023', team: 'Red Bull', position: 1 },
    { season: '2024', team: 'Red Bull', position: 3 },
    { season: '2019', team: 'Ferrari', position: 2 },
    { season: '2020', team: 'Ferrari', position: 6 },
    { season: '2021', team: 'Ferrari', position: 3 },
    { season: '2022', team: 'Ferrari', position: 2 },
    { season: '2023', team: 'Ferrari', position: 3 },
    { season: '2024', team: 'Ferrari', position: 2 },
    { season: '2019', team: 'McLaren', position: 4 },
    { season: '2020', team: 'McLaren', position: 3 },
    { season: '2021', team: 'McLaren', position: 4 },
    { season: '2022', team: 'McLaren', position: 5 },
    { season: '2023', team: 'McLaren', position: 4 },
    { season: '2024', team: 'McLaren', position: 1 },
    { season: '2019', team: 'Alpine', position: 5 },
    { season: '2020', team: 'Alpine', position: 5 },
    { season: '2021', team: 'Alpine', position: 5 },
    { season: '2022', team: 'Alpine', position: 4 },
    { season: '2023', team: 'Alpine', position: 6 },
    { season: '2024', team: 'Alpine', position: 6 },
  ],
  encoding: {
    x: { field: 'season', type: 'ordinal' },
    y: {
      field: 'position',
      type: 'quantitative',
      scale: { reverse: true, zero: false },
      axis: { values: [1, 2, 3, 4, 5, 6], format: 'ordinal' },
    },
    color: { field: 'team', type: 'nominal' },
  },
  endpointLabels: {
    ends: 'both',
    content: 'label',
    showMarker: false,
  },
  legend: { show: false },
  chrome: {
    title: 'McLaren Went From Midfield to Champions',
    subtitle: 'Formula 1 constructors championship, final position by season',
    source: 'Source: FIA official standings',
  },
};
```

What each field does:

- `scale: { reverse: true }` flips the y range so rank 1 renders at the top. `zero: false` keeps rank 0 off the axis.
- `axis: { values: [1, 2, 3, 4, 5, 6], format: 'ordinal' }` pins one tick per rank and formats them as ordinals. `format: 'ordinal'` is an OpenChart extension to the d3-format strings; it works anywhere a format string does.
- `interpolate: 'monotone'` curves the lines through rank changes without overshooting; `point: true` marks every step.
- `endpointLabels.content: 'label'` puts the name alone at both ends (the rank is already on the axis). `showMarker: false` skips the open-circle end markers, which would double up with the step points.

If your data has raw scores instead of precomputed ranks, derive the rank with the window transform first:

```ts
transform: [
  {
    window: [{ op: 'rank', field: 'points', as: 'position' }],
    sort: [{ field: 'points', order: 'descending' }],
    groupby: ['season'],
  },
],
```

**Live example**: [Bump](https://tryopendata.github.io/openchart/?story=testing--fixtures--bump-constructors)

---

## Range (dumbbell)

When the story is the size of the change per category rather than trajectories over time, use `mark: "range"`: one row per category, a dot at the start and end values. Set `mark: { type: 'range', style: 'arrow' }` for an arrowhead at the end value, or `style: 'bar'` for a plain floating bar.

```json demo title="Life expectancy, 2000 and 2023" source="UN World Population Prospects 2024" height=440
{
  "mark": "range",
  "data": [
    { "country": "Japan", "y2000": 81.1, "y2023": 84.7 },
    { "country": "South Korea", "y2000": 76, "y2023": 84.3 },
    { "country": "USA", "y2000": 76.7, "y2023": 79.3 },
    { "country": "China", "y2000": 71.6, "y2023": 78.6 },
    { "country": "Brazil", "y2000": 70.1, "y2023": 75.8 },
    { "country": "Russia", "y2000": 65.5, "y2023": 73 },
    { "country": "India", "y2000": 62.7, "y2023": 72 },
    { "country": "Nigeria", "y2000": 46.5, "y2023": 54.6 }
  ],
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": { "field": "y2023", "order": "ascending" }
    },
    "x": {
      "field": "y2000",
      "type": "quantitative",
      "title": "2000",
      "axis": { "title": "Life expectancy at birth (years)" }
    },
    "x2": { "field": "y2023", "type": "quantitative", "title": "2023" }
  },
  "chrome": {
    "title": "India gained 9.3 years of life expectancy between 2000 and 2023, the US 2.6",
    "subtitle": "Life expectancy at birth, 2000 (gray) vs. 2023 (accent), selected countries"
  }
}
```

**Live examples**: [Dumbbell](https://tryopendata.github.io/openchart/?story=testing--fixtures--range-dumbbell) | [Arrow](https://tryopendata.github.io/openchart/?story=testing--fixtures--range-arrow) | [Range bar](https://tryopendata.github.io/openchart/?story=testing--fixtures--range-bar)

---

## Picking within the family

| You want to show | Use |
|------------------|-----|
| Before vs after for many series, values matter | Slope |
| Rank trajectories across several periods | Bump |
| Size of change per category, one period pair | Range (dumbbell or arrow) |
| Continuous values over many periods | Plain [multi-series line](chart-types.md#line) |

---

## Related docs

- [Chart types](chart-types.md) for the full gallery of supported forms
- [Spec reference](spec-reference.md) for field-by-field type details, including `endpointLabels` and scale options
- [Visualization patterns](agent-patterns.md) for more data storytelling recipes

## Grouped bar lists and uncertainty

Bar lists support `encoding.group` for section headers, `sort: null` to retain input order, an explicit `encoding.value.scale.domain` for comparisons, and x reference lines such as a lift baseline at 1. `labels.format`, `prefix` and `suffix` control the displayed row value. Bar and range marks separately support `labels.content` to compose names and values. For estimates with uncertainty, layer an `errorbar` with a `point` instead of encoding the interval as a filled bar. Supply all interval bounds upstream. See [static rendering](static-rendering.md) for server output.
