Skip to content
OpenChart

How to make a slope chart in JavaScript

A slope chart compares two moments with one line per item. This post uses fatal accidents at 11 airlines and covers how to choose the two endpoints.

19802012September 3.57March 15.20September 7.67March 16.04September ice fell 53% from 1980 to 2012, and March ice changedlittleAverage Arctic sea ice extent in March and September, million km²19802012September 3.57March 15.20September 7.67March 16.04September ice fell 53% from 1980 to 2012, and March ice changedlittleAverage Arctic sea ice extent in March and September, million km²
Arctic sea ice extent in March and September, 1980 and 2012. Source: NSIDC Sea Ice Index v4.0 (NOAA at NSIDC).

Made with OpenChart. How to build this line chart

Fatal accidents at 56 airlines fell from 122 in 1985-99 to 37 in 2000-14, according to FiveThirtyEight’s airline safety data. Did every airline improve, or did a few carry the drop? A slope chart answers that in one look: each period gets a vertical edge, each airline gets a line between its two counts, and the steeper the line, the bigger the change.

A slope chart of airline accidents

The chart keeps the 11 airlines with four or more fatal accidents in the first period.

1985-992000-14Aeroflot 1Delta 2United 2US Airways 2China 1American 3Korean Air 0Ethiopian 2Air France 2Thai Airways 1Philippine 1Aeroflot 14Delta 12United 8US Airways 7China 6American 5Korean Air 5Ethiopian 5Air France 4Thai Airways 4Philippine 4Fatal accidents at 11 airlines fell from 74 to 17Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37.1985-992000-14Aeroflot 1Delta 2United 2US Airways 2China 1American 3Korean Air 0Ethiopian 2Air France 2Thai Airways 1Philippine 1Aeroflot 14Delta 12United 8US Airways 7China 6American 5Korean Air 5Ethiopian 5Air France 4Thai Airways 4Philippine 4Fatal accidents at 11 airlines fell from 74 to 17Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37.
Live example. Source: FiveThirtyEight, Airline Safety.

Made with OpenChart. How to build this line chart

{
  "mark": "line",
  "data": [
    {
      "airline": "Aeroflot",
      "period": "1985-99",
      "accidents": 14
    },
    {
      "airline": "Aeroflot",
      "period": "2000-14",
      "accidents": 1
    },
    {
      "airline": "Delta",
      "period": "1985-99",
      "accidents": 12
    },
    {
      "airline": "Delta",
      "period": "2000-14",
      "accidents": 2
    },
    {
      "airline": "United",
      "period": "1985-99",
      "accidents": 8
    },
    {
      "airline": "United",
      "period": "2000-14",
      "accidents": 2
    },
    // … 16 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "period",
      "type": "ordinal"
    },
    "y": {
      "field": "accidents",
      "type": "quantitative",
      "axis": false
    },
    "color": {
      "field": "airline",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "maxSeries": 11
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "maxSeries": 11
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "period",
      "type": "ordinal"
    },
    "y": {
      "field": "accidents",
      "type": "quantitative",
      "axis": false
    },
    "color": {
      "field": "airline",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "maxSeries": 11
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "maxSeries": 11
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37."
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "period",
      "type": "ordinal"
    },
    "y": {
      "field": "accidents",
      "type": "quantitative",
      "axis": false
    },
    "color": {
      "field": "airline",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "maxSeries": 11
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "maxSeries": 11
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37."
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "period",
      "type": "ordinal"
    },
    "y": {
      "field": "accidents",
      "type": "quantitative",
      "axis": false
    },
    "color": {
      "field": "airline",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "maxSeries": 11
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "maxSeries": 11
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37."
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "period",
      "type": "ordinal"
    },
    "y": {
      "field": "accidents",
      "type": "quantitative",
      "axis": false
    },
    "color": {
      "field": "airline",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "maxSeries": 11
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "maxSeries": 11
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99. All 56 airlines: 122 to 37."
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Every line falls, and Aeroflot’s falls furthest. The y axis is gone because the labels carry the numbers: each airline’s name and count sit at both ends, so nobody has to match a color to a legend. All lines share one color because the finding is about the group. A merged airline goes by the first name in the source, so “Delta” is the source’s Delta / Northwest.

On a phone the left labels go. Both label columns are as wide as the wider one, and two columns of names leave a 390-pixel phone about 40 pixels for the lines. The phone layout puts a y axis on the left for the first-period counts and keeps the names on the right, next to the counts the reader compares.

Slope chart vs grouped bars

Grouped bars hold the same 22 numbers and rank the airlines within one period better than a slope chart can. To see which airlines improved, though, the reader has to find and compare the bars in pairs.

02468101214Fatal accidentsAeroflotDeltaUnitedUS AirwaysChinaAmericanKorean AirEthiopianAir FranceThai AirwaysPhilippine1411228272615350524241411985-992000-14Fatal accidents at 11 airlines fell from 74 to 17Fatal accidents per 15-year period, airlines with 4 or more in 1985-9902468101214Fatal accidentsAeroflotDeltaUnitedUS AirwaysChinaAmericanKorean AirEthiopianAir FranceThai AirwaysPhilippine1411228272615350524241411985-992000-14Fatal accidents at 11 airlines fell from 74 to 17Fatal accidents per 15-year period, airlines with 4 or more in 1985-99
Fatal accidents by airline, 1985-99 and 2000-14, as grouped bars. Source: FiveThirtyEight, Airline Safety.

Made with OpenChart. How to build this bar chart

{
  "mark": "bar",
  "data": [
    {
      "airline": "Aeroflot",
      "period": "1985-99",
      "accidents": 14
    },
    {
      "airline": "Aeroflot",
      "period": "2000-14",
      "accidents": 1
    },
    {
      "airline": "Delta",
      "period": "1985-99",
      "accidents": 12
    },
    {
      "airline": "Delta",
      "period": "2000-14",
      "accidents": 2
    },
    {
      "airline": "United",
      "period": "1985-99",
      "accidents": 8
    },
    {
      "airline": "United",
      "period": "2000-14",
      "accidents": 2
    },
    // … 16 more rows; Copy includes them
  ],
  "encoding": {
    "y": {
      "field": "airline",
      "type": "nominal",
      "sort": null
    },
    "x": {
      "field": "accidents",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Fatal accidents"
      }
    },
    "color": {
      "field": "period",
      "type": "nominal",
      "scale": {
        "domain": [
          "1985-99",
          "2000-14"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "airline",
      "type": "nominal",
      "sort": null
    },
    "x": {
      "field": "accidents",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Fatal accidents"
      }
    },
    "color": {
      "field": "period",
      "type": "nominal",
      "scale": {
        "domain": [
          "1985-99",
          "2000-14"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "airline",
      "type": "nominal",
      "sort": null
    },
    "x": {
      "field": "accidents",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Fatal accidents"
      }
    },
    "color": {
      "field": "period",
      "type": "nominal",
      "scale": {
        "domain": [
          "1985-99",
          "2000-14"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "airline",
      "type": "nominal",
      "sort": null
    },
    "x": {
      "field": "accidents",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Fatal accidents"
      }
    },
    "color": {
      "field": "period",
      "type": "nominal",
      "scale": {
        "domain": [
          "1985-99",
          "2000-14"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 22 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "airline",
      "type": "nominal",
      "sort": null
    },
    "x": {
      "field": "accidents",
      "type": "quantitative",
      "stack": null,
      "axis": {
        "title": "Fatal accidents"
      }
    },
    "color": {
      "field": "period",
      "type": "nominal",
      "scale": {
        "domain": [
          "1985-99",
          "2000-14"
        ]
      }
    }
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        },
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "Fatal accidents at 11 airlines fell from 74 to 17",
    "subtitle": "Fatal accidents per 15-year period, airlines with 4 or more in 1985-99"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Choosing the endpoints

Two points hide everything between them, so the choice of endpoints is part of the argument. The airline data comes in two fixed periods, but Arctic sea ice has been tracked by satellite since 1979, so any two years can be the endpoints. September is each year’s low point for ice and March its high. September 1980 has the most ice in the record and September 2012 the least, so this pair shows the steepest drop the data allows.

19802012September 3.57March 15.20September 7.67March 16.04September ice fell 53% from 1980 to 2012, and March ice changedlittleAverage Arctic sea ice extent in March and September, million km²19802012September 3.57March 15.20September 7.67March 16.04September ice fell 53% from 1980 to 2012, and March ice changedlittleAverage Arctic sea ice extent in March and September, million km²
Arctic sea ice extent in March and September, 1980 and 2012. Source: NSIDC Sea Ice Index v4.0 (NOAA at NSIDC).

Made with OpenChart. How to build this line chart

{
  "mark": "line",
  "data": [
    {
      "month": "September",
      "year": "1980",
      "extent": 7.67
    },
    {
      "month": "September",
      "year": "2012",
      "extent": 3.57
    },
    {
      "month": "March",
      "year": "1980",
      "extent": 16.04
    },
    {
      "month": "March",
      "year": "2012",
      "extent": 15.2
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "month",
      "type": "nominal",
      "scale": {
        "domain": [
          "September",
          "March"
        ]
      }
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "format": ".2f"
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "format": ".2f"
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice fell 53% from 1980 to 2012, and March ice changed little",
    "subtitle": "Average Arctic sea ice extent in March and September, million km²"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "line",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "month",
      "type": "nominal",
      "scale": {
        "domain": [
          "September",
          "March"
        ]
      }
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "format": ".2f"
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "format": ".2f"
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice fell 53% from 1980 to 2012, and March ice changed little",
    "subtitle": "Average Arctic sea ice extent in March and September, million km²"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "line",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "month",
      "type": "nominal",
      "scale": {
        "domain": [
          "September",
          "March"
        ]
      }
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "format": ".2f"
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "format": ".2f"
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice fell 53% from 1980 to 2012, and March ice changed little",
    "subtitle": "Average Arctic sea ice extent in March and September, million km²"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "line",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "month",
      "type": "nominal",
      "scale": {
        "domain": [
          "September",
          "March"
        ]
      }
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "format": ".2f"
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "format": ".2f"
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice fell 53% from 1980 to 2012, and March ice changed little",
    "subtitle": "Average Arctic sea ice extent in March and September, million km²"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const spec: ChartSpec = {
  "mark": "line",
  "data": [/* 4 rows, as in the Spec tab; Copy includes them */],
  "encoding": {
    "x": {
      "field": "year",
      "type": "ordinal"
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": false,
      "scale": {
        "zero": false
      }
    },
    "color": {
      "field": "month",
      "type": "nominal",
      "scale": {
        "domain": [
          "September",
          "March"
        ]
      }
    }
  },
  "endpointLabels": {
    "ends": "both",
    "content": "label value",
    "format": ".2f"
  },
  "overrides": {
    "compact": {
      "encoding": {
        "y": {
          "axis": {
            "tickCount": 4
          }
        }
      },
      "endpointLabels": {
        "ends": "end",
        "content": "label value",
        "format": ".2f"
      }
    }
  },
  "legend": {
    "show": false
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        },
        {
          "light": "#64748b",
          "dark": "#94a3b8"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice fell 53% from 1980 to 2012, and March ice changed little",
    "subtitle": "Average Arctic sea ice extent in March and September, million km²"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Every September since 2012 has had more ice than 2012 did, and the slope hides that. The full series shows where the two endpoints sit.

1980199020002010202002468Million km²19807.6720123.57September ice reached its record low in 2012 and has stayed above itsinceAverage Arctic sea ice extent in September, million km², 1979-20251980199020002010202002468Million km²19807.6720123.57September ice reached its record low in 2012 and has stayed above itsinceAverage Arctic sea ice extent in September, million km², 1979-2025
September Arctic sea ice extent, 1979 to 2025. Source: NSIDC Sea Ice Index v4.0 (NOAA at NSIDC).

Made with OpenChart. How to build this line chart

{
  "mark": {
    "type": "line",
    "interpolate": "linear"
  },
  "data": [
    {
      "year": "1979",
      "extent": 7.05
    },
    {
      "year": "1980",
      "extent": 7.67
    },
    {
      "year": "1981",
      "extent": 7.14
    },
    {
      "year": "1982",
      "extent": 7.3
    },
    {
      "year": "1983",
      "extent": 7.39
    },
    {
      "year": "1984",
      "extent": 6.81
    },
    // … 41 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": {
        "title": "Million km²",
        "tickCount": 5
      },
      "scale": {
        "domain": [
          0,
          8
        ],
        "zero": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "1980",
      "y": 7.67,
      "text": "**1980**\n7.67",
      "anchor": "top",
      "offset": {
        "dx": 28,
        "dy": -30
      },
      "connector": "curve"
    },
    {
      "type": "text",
      "x": "2012",
      "y": 3.57,
      "text": "**2012**\n3.57",
      "anchor": "bottom",
      "offset": {
        "dx": 0,
        "dy": 40
      },
      "connector": "curve"
    }
  ],
  "labels": false,
  "responsive": {
    "compactAnnotationLimit": 2
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice reached its record low in 2012 and has stayed above it since",
    "subtitle": "Average Arctic sea ice extent in September, million km², 1979-2025"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 47 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": {
        "title": "Million km²",
        "tickCount": 5
      },
      "scale": {
        "domain": [
          0,
          8
        ],
        "zero": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "1980",
      "y": 7.67,
      "text": "**1980**\n7.67",
      "anchor": "top",
      "offset": {
        "dx": 28,
        "dy": -30
      },
      "connector": "curve"
    },
    {
      "type": "text",
      "x": "2012",
      "y": 3.57,
      "text": "**2012**\n3.57",
      "anchor": "bottom",
      "offset": {
        "dx": 0,
        "dy": 40
      },
      "connector": "curve"
    }
  ],
  "labels": false,
  "responsive": {
    "compactAnnotationLimit": 2
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice reached its record low in 2012 and has stayed above it since",
    "subtitle": "Average Arctic sea ice extent in September, million km², 1979-2025"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 47 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": {
        "title": "Million km²",
        "tickCount": 5
      },
      "scale": {
        "domain": [
          0,
          8
        ],
        "zero": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "1980",
      "y": 7.67,
      "text": "**1980**\n7.67",
      "anchor": "top",
      "offset": {
        "dx": 28,
        "dy": -30
      },
      "connector": "curve"
    },
    {
      "type": "text",
      "x": "2012",
      "y": 3.57,
      "text": "**2012**\n3.57",
      "anchor": "bottom",
      "offset": {
        "dx": 0,
        "dy": 40
      },
      "connector": "curve"
    }
  ],
  "labels": false,
  "responsive": {
    "compactAnnotationLimit": 2
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice reached its record low in 2012 and has stayed above it since",
    "subtitle": "Average Arctic sea ice extent in September, million km², 1979-2025"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 47 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": {
        "title": "Million km²",
        "tickCount": 5
      },
      "scale": {
        "domain": [
          0,
          8
        ],
        "zero": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "1980",
      "y": 7.67,
      "text": "**1980**\n7.67",
      "anchor": "top",
      "offset": {
        "dx": 28,
        "dy": -30
      },
      "connector": "curve"
    },
    {
      "type": "text",
      "x": "2012",
      "y": 3.57,
      "text": "**2012**\n3.57",
      "anchor": "bottom",
      "offset": {
        "dx": 0,
        "dy": 40
      },
      "connector": "curve"
    }
  ],
  "labels": false,
  "responsive": {
    "compactAnnotationLimit": 2
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice reached its record low in 2012 and has stayed above it since",
    "subtitle": "Average Arctic sea ice extent in September, million km², 1979-2025"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 47 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "linear"
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "extent",
      "type": "quantitative",
      "axis": {
        "title": "Million km²",
        "tickCount": 5
      },
      "scale": {
        "domain": [
          0,
          8
        ],
        "zero": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "1980",
      "y": 7.67,
      "text": "**1980**\n7.67",
      "anchor": "top",
      "offset": {
        "dx": 28,
        "dy": -30
      },
      "connector": "curve"
    },
    {
      "type": "text",
      "x": "2012",
      "y": 3.57,
      "text": "**2012**\n3.57",
      "anchor": "bottom",
      "offset": {
        "dx": 0,
        "dy": 40
      },
      "connector": "curve"
    }
  ],
  "labels": false,
  "responsive": {
    "compactAnnotationLimit": 2
  },
  "theme": {
    "colors": {
      "categorical": [
        {
          "light": "#0e7490",
          "dark": "#22a3c4"
        }
      ]
    }
  },
  "chrome": {
    "title": "September ice reached its record low in 2012 and has stayed above it since",
    "subtitle": "Average Arctic sea ice extent in September, million km², 1979-2025"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

When the path between the points matters, or you have three or more time points, use a line chart.

How many lines fit

Past about a dozen lines, the crossings and labels collide. The airline chart has 11 because it keeps only the airlines with four or more fatal accidents in 1985-99, and the subtitle says so. State the selection rule whenever you show a subset.

Picking airlines for a bad first period also builds in some improvement. Part of any bad record is bad luck, which rarely repeats, so the second count tends to fall even if nothing changed. Statisticians call this regression to the mean. The subtitle gives the total for all 56 airlines, which fell too.

Lines that end at the same value stack their labels, and the engine spaces them apart. Setting showLeader adds a short line from a moved label back to its point when the pairing gets unclear.

The spec

A slope chart is a line chart with two values on the x axis. In the airline spec, mark is "line" and encoding.x is the period field as ordinal, which puts one tick at each edge. axis: false on encoding.y removes the axis and its gridlines.

color gives each airline its own line, and theme.colors.categorical lists one palette color per airline, all the same teal. Each is a { light, dark } pair, so the labels switch to a lighter teal on a dark page and stay readable. endpointLabels with ends: "both" and content: "label value" prints the name and count at each edge, and legend: { show: false } drops the legend. The endpoint labels page lists the other label options.

overrides.compact applies below 400 pixels wide. It turns the y axis back on and sets ends: "end", which hands the lines the width the left labels took.

To show the size of each gap rather than its direction, a range chart draws the two values as a floating bar.

For more than two periods, the slope and bump page builds a bump chart, which ranks items across many periods.