# Slope and bump

> Compare two moments with a slope chart or follow rank across many periods with a bump chart. Both are line charts with a few extra spec fields.

A slope chart draws one line per series between two points in time, so every crossing is a change in rank and every steep line is a large move. A bump chart plots rank rather than value across several periods, and shows who moved up or down at each step.

Neither is a separate mark. Both are `mark: "line"` with a few public spec fields. Use a regular [line chart](/docs/change-over-time/line/) when the exact values over many periods matter more than the order, and a [range chart](/docs/comparison/range/) when you want the size of each gap between two values.

## A slope chart

Two ordinal x values, one line per brand. The values live on the labels, so `axis: false` removes the y axis and its gridlines. Line marks already fit the y axis to the data range (`zero: false`) and curve monotonically. The recipe sets both explicitly so the spec stays readable on its own. `endpointLabels` with `ends: "both"` puts a label column at each edge.

```json
{
  "mark": "line",
  "data": [
    {
      "year": "2019",
      "brand": "Samsung",
      "share": 0.216
    },
    {
      "year": "2024",
      "brand": "Samsung",
      "share": 0.19
    },
    {
      "year": "2019",
      "brand": "Huawei",
      "share": 0.176
    },
    {
      "year": "2024",
      "brand": "Huawei",
      "share": 0.043
    },
    {
      "year": "2019",
      "brand": "Apple",
      "share": 0.139
    },
    {
      "year": "2024",
      "brand": "Apple",
      "share": 0.187
    },
    {
      "year": "2019",
      "brand": "Xiaomi",
      "share": 0.092
    },
    {
      "year": "2024",
      "brand": "Xiaomi",
      "share": 0.136
    },
    {
      "year": "2019",
      "brand": "Oppo",
      "share": 0.083
    },
    {
      "year": "2024",
      "brand": "Oppo",
      "share": 0.087
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "brand",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "format": ".0%"
  },
  "legend": {
    "show": false
  },
  "chrome": {
    "title": "Huawei's share fell from 18% to 4% as Apple and Xiaomi gained",
    "subtitle": "Share of global smartphone shipments, 2019 vs 2024"
  }
}
```

## Different labels on each side

`content` takes an object to set the two columns separately. Here `leading` joins the name and value on the left and `trailing` prints the value alone on the right, so the name is not repeated. Because the spec sets `endpointLabels` explicitly, the label columns stay at narrow widths where automatic endpoint labels would hand off to a legend.

```json
{
  "mark": "line",
  "data": [
    {
      "year": "2019",
      "brand": "Samsung",
      "share": 0.216
    },
    {
      "year": "2024",
      "brand": "Samsung",
      "share": 0.19
    },
    {
      "year": "2019",
      "brand": "Huawei",
      "share": 0.176
    },
    {
      "year": "2024",
      "brand": "Huawei",
      "share": 0.043
    },
    {
      "year": "2019",
      "brand": "Apple",
      "share": 0.139
    },
    {
      "year": "2024",
      "brand": "Apple",
      "share": 0.187
    },
    {
      "year": "2019",
      "brand": "Xiaomi",
      "share": 0.092
    },
    {
      "year": "2024",
      "brand": "Xiaomi",
      "share": 0.136
    },
    {
      "year": "2019",
      "brand": "Oppo",
      "share": 0.083
    },
    {
      "year": "2024",
      "brand": "Oppo",
      "share": 0.087
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "brand",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": {
      "leading": "label value",
      "trailing": "value"
    },
    "format": ".0%"
  },
  "legend": {
    "show": false
  },
  "chrome": {
    "title": "Name and value on the left, value alone on the right",
    "subtitle": "Share of global smartphone shipments, 2019 vs 2024"
  }
}
```

## A bump chart

The y axis is the finishing position. `scale: { reverse: true }` puts first place at the top, and `axis.values` with `format: "ordinal"` prints one tick per rank as 1st, 2nd and so on. `point: true` marks every step. Line marks already curve monotonically; the recipe sets `interpolate: "monotone"` explicitly so the spec stays readable on its own. Series that tie share a row.

```json
{
  "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"
  }
}
```

## Ranks from scores

If your data holds scores rather than ranks, derive the rank with a `window` transform. `op: "rank"` ranks the rows within each group, `groupby` makes each date its own ranking, and `sort` sets the direction. The result lands in the field named by `as`, which the y channel then reads. At the first date every index starts at 0% and ties for first.

```json
{
  "mark": {
    "type": "line",
    "interpolate": "monotone",
    "point": true
  },
  "data": [
    {
      "date": "2022-01-01",
      "totalReturn": 0,
      "index": "S&P 500"
    },
    {
      "date": "2022-04-01",
      "totalReturn": -5.3,
      "index": "S&P 500"
    },
    {
      "date": "2022-07-01",
      "totalReturn": -13.1,
      "index": "S&P 500"
    },
    {
      "date": "2022-10-01",
      "totalReturn": -17.7,
      "index": "S&P 500"
    },
    {
      "date": "2023-01-01",
      "totalReturn": -18.1,
      "index": "S&P 500"
    },
    {
      "date": "2023-04-01",
      "totalReturn": -8.2,
      "index": "S&P 500"
    },
    {
      "date": "2023-07-01",
      "totalReturn": 1.5,
      "index": "S&P 500"
    },
    {
      "date": "2023-10-01",
      "totalReturn": -0.8,
      "index": "S&P 500"
    },
    {
      "date": "2024-01-01",
      "totalReturn": 3.4,
      "index": "S&P 500"
    },
    {
      "date": "2024-04-01",
      "totalReturn": 12.8,
      "index": "S&P 500"
    },
    {
      "date": "2024-07-01",
      "totalReturn": 20.6,
      "index": "S&P 500"
    },
    {
      "date": "2024-10-01",
      "totalReturn": 29.2,
      "index": "S&P 500"
    },
    {
      "date": "2025-01-01",
      "totalReturn": 29.3,
      "index": "S&P 500"
    },
    {
      "date": "2025-04-01",
      "totalReturn": 33.5,
      "index": "S&P 500"
    },
    {
      "date": "2025-07-01",
      "totalReturn": 39.8,
      "index": "S&P 500"
    },
    {
      "date": "2025-10-01",
      "totalReturn": 46.2,
      "index": "S&P 500"
    },
    {
      "date": "2022-01-01",
      "totalReturn": 0,
      "index": "NASDAQ"
    },
    {
      "date": "2022-04-01",
      "totalReturn": -9.1,
      "index": "NASDAQ"
    },
    {
      "date": "2022-07-01",
      "totalReturn": -22.4,
      "index": "NASDAQ"
    },
    {
      "date": "2022-10-01",
      "totalReturn": -29.5,
      "index": "NASDAQ"
    },
    {
      "date": "2023-01-01",
      "totalReturn": -33.1,
      "index": "NASDAQ"
    },
    {
      "date": "2023-04-01",
      "totalReturn": -15.8,
      "index": "NASDAQ"
    },
    {
      "date": "2023-07-01",
      "totalReturn": 2.5,
      "index": "NASDAQ"
    },
    {
      "date": "2023-10-01",
      "totalReturn": -3.6,
      "index": "NASDAQ"
    },
    {
      "date": "2024-01-01",
      "totalReturn": -4.1,
      "index": "NASDAQ"
    },
    {
      "date": "2024-04-01",
      "totalReturn": 12.4,
      "index": "NASDAQ"
    },
    {
      "date": "2024-07-01",
      "totalReturn": 24.8,
      "index": "NASDAQ"
    },
    {
      "date": "2024-10-01",
      "totalReturn": 36.9,
      "index": "NASDAQ"
    },
    {
      "date": "2025-01-01",
      "totalReturn": 39.1,
      "index": "NASDAQ"
    },
    {
      "date": "2025-04-01",
      "totalReturn": 48.2,
      "index": "NASDAQ"
    },
    {
      "date": "2025-07-01",
      "totalReturn": 56.8,
      "index": "NASDAQ"
    },
    {
      "date": "2025-10-01",
      "totalReturn": 64.7,
      "index": "NASDAQ"
    },
    {
      "date": "2022-01-01",
      "totalReturn": 0,
      "index": "Dow Jones"
    },
    {
      "date": "2022-04-01",
      "totalReturn": -4.1,
      "index": "Dow Jones"
    },
    {
      "date": "2022-07-01",
      "totalReturn": -9.5,
      "index": "Dow Jones"
    },
    {
      "date": "2022-10-01",
      "totalReturn": -13.2,
      "index": "Dow Jones"
    },
    {
      "date": "2023-01-01",
      "totalReturn": -7,
      "index": "Dow Jones"
    },
    {
      "date": "2023-04-01",
      "totalReturn": -1.8,
      "index": "Dow Jones"
    },
    {
      "date": "2023-07-01",
      "totalReturn": 4.5,
      "index": "Dow Jones"
    },
    {
      "date": "2023-10-01",
      "totalReturn": 2.2,
      "index": "Dow Jones"
    },
    {
      "date": "2024-01-01",
      "totalReturn": 7.9,
      "index": "Dow Jones"
    },
    {
      "date": "2024-04-01",
      "totalReturn": 12.1,
      "index": "Dow Jones"
    },
    {
      "date": "2024-07-01",
      "totalReturn": 17.4,
      "index": "Dow Jones"
    },
    {
      "date": "2024-10-01",
      "totalReturn": 24,
      "index": "Dow Jones"
    },
    {
      "date": "2025-01-01",
      "totalReturn": 25.8,
      "index": "Dow Jones"
    },
    {
      "date": "2025-04-01",
      "totalReturn": 30.4,
      "index": "Dow Jones"
    },
    {
      "date": "2025-07-01",
      "totalReturn": 36.1,
      "index": "Dow Jones"
    },
    {
      "date": "2025-10-01",
      "totalReturn": 42.5,
      "index": "Dow Jones"
    },
    {
      "date": "2022-01-01",
      "totalReturn": 0,
      "index": "Russell 2000"
    },
    {
      "date": "2022-04-01",
      "totalReturn": -7.8,
      "index": "Russell 2000"
    },
    {
      "date": "2022-07-01",
      "totalReturn": -17.2,
      "index": "Russell 2000"
    },
    {
      "date": "2022-10-01",
      "totalReturn": -21.5,
      "index": "Russell 2000"
    },
    {
      "date": "2023-01-01",
      "totalReturn": -20.5,
      "index": "Russell 2000"
    },
    {
      "date": "2023-04-01",
      "totalReturn": -13.2,
      "index": "Russell 2000"
    },
    {
      "date": "2023-07-01",
      "totalReturn": -4.5,
      "index": "Russell 2000"
    },
    {
      "date": "2023-10-01",
      "totalReturn": -8.1,
      "index": "Russell 2000"
    },
    {
      "date": "2024-01-01",
      "totalReturn": -7.1,
      "index": "Russell 2000"
    },
    {
      "date": "2024-04-01",
      "totalReturn": -1.8,
      "index": "Russell 2000"
    },
    {
      "date": "2024-07-01",
      "totalReturn": 3.5,
      "index": "Russell 2000"
    },
    {
      "date": "2024-10-01",
      "totalReturn": 8.2,
      "index": "Russell 2000"
    },
    {
      "date": "2025-01-01",
      "totalReturn": 8.4,
      "index": "Russell 2000"
    },
    {
      "date": "2025-04-01",
      "totalReturn": 12.8,
      "index": "Russell 2000"
    },
    {
      "date": "2025-07-01",
      "totalReturn": 17.5,
      "index": "Russell 2000"
    },
    {
      "date": "2025-10-01",
      "totalReturn": 21.5,
      "index": "Russell 2000"
    }
  ],
  "transform": [
    {
      "window": [
        {
          "op": "rank",
          "field": "totalReturn",
          "as": "position"
        }
      ],
      "sort": [
        {
          "field": "totalReturn",
          "order": "descending"
        }
      ],
      "groupby": [
        "date"
      ]
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%b '%y",
        "tickCount": 6
      }
    },
    "y": {
      "field": "position",
      "type": "quantitative",
      "scale": {
        "reverse": true,
        "zero": false
      },
      "axis": {
        "values": [
          1,
          2,
          3,
          4
        ],
        "format": "ordinal"
      }
    },
    "color": {
      "field": "index",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label",
    "showMarker": false
  },
  "legend": {
    "show": false
  },
  "chrome": {
    "title": "The window transform turns scores into ranks",
    "subtitle": "Rank of cumulative total return among four US equity indices, quarterly"
  }
}
```

## Fields that matter

| Field | What it does |
| --- | --- |
| `mark` | `"line"`. For a bump chart, an object with `point: true`, plus `interpolate: "monotone"` if you want it explicit. |
| `encoding.y.axis` | `false` removes the axis, as on a slope chart. `values` and `format: "ordinal"` print rank ticks. |
| `encoding.y.scale` | `zero: false` is already the line default and is set for clarity. `reverse: true` puts rank 1 at the top. |
| `endpointLabels.ends` | `"both"` adds a label column on the left edge as well as the right. |
| `endpointLabels.content` | `"label"`, `"value"` or `"label value"`, or an object with `leading` and `trailing`. |
| `transform` | A `window` rank turns scores into positions grouped by period. |
| `legend` | `{ show: false }` hides the legend when the labels name every series. |

## Related

- [Line](/docs/change-over-time/line/) for values over many periods.
- [Range](/docs/comparison/range/) for the gap between two values.
- [Bar](/docs/comparison/bar/) for a ranking at a single moment.
- [Sparkline](/docs/change-over-time/sparkline/) for a trend with no axes.
- [Marks reference](/docs/spec/marks/) lists the channels and options each mark type takes.
