Skip to content
InsightCharts

Search

Search guides and components

Slope chart

Connects each entity's value at two (or a few) points with a straight line, labelled with name and value at both ends.

Use when
Before / after for 3 to about 15 entities when the change in level and in ordering both matter; pair with highlight to emphasise one line.
Avoid when
Five or more time points (use line chart); when only the ordering matters (use bump chart); when only the size of each gap matters (use dumbbell chart or arrow chart).

Preview

The UK's coal share of electricity fell from 39% to 1% between 2012 and 2023

Share of electricity generated from coal, 2012 and 2023

Source: Ember (rounded) · Figures are approximate, for illustration

Composition

Used in

1 infographic uses slope chart.

Infographics

1

A landscape spread of up to eleven small illustrations of one subject, each a different graphic form, in three bands of unequal panels: a statement in large type, spokes round an icon and a network of circles; a smooth trend with its peak labelled, nested squares and a slope chart; a pill ranking, a treemap, a tile map and sized circles; and a closing row of icon statements.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/slope-chart

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { SlopeChart } from "insightcharts";

Examples

Coloured by direction

London's employment rate rose from 68.9% to 75.1% between 2014 and 2024

Employment rate, ages 16 to 64, 2014 and 2024

Illustrative figures.

Long format, three periods

Streaming's share of recorded music revenue rose from 9% to 67% between 2012 and 2023

Share of recorded music revenue by format, 2012, 2016 and 2023

Illustrative figures.

Stress: 20 entities with close values and long names

Life expectancy in Ethiopia rose from 39 to 65 years between 2000 and 2022

Life expectancy at birth, years, 2000 and 2022. Bangladesh rose from 49 to 73.

Illustrative figures.

Props

PropTypeDefaultDescription
seriesrequiredstringEntity field: one line each.
xstringPeriod field for long data. Omit when each row is an entity with one column per period.
yrequiredstring | string[]Value field (long data), or the period columns in order (one row per entity).
colorBy"none" | "direction" | "series""none"Accent for all lines, positive / negative by direction, or one hue per entity (up to 8).
good"up" | "down""up"Direction that takes the positive colour when colouring by direction.
labels"both" | "end"Entity names at both ends or only the end. Default: both; end only on narrow screens.
namesRecord<string, string>Display names for entity keys and period columns.
Common chart props 29

Every chart built with defineChart accepts these on top of its own props.

PropTypeDescription
dataDataInputRows, CSV text, a URL, { url, path }, an async function, or an Arrow-style table. Omit inside <InsightData>.
transformTransform | Transform[]A pipeline of transforms applied before drawing.
titlestringThe title. One plain statement of what the data shows, with the number and the period ("Monthly churn fell from 4.2% to 2.1% in 2024"), or a plain label ("Monthly churn, 2024"). One clause, no figures of speech.
subtitlestringMeasure, unit, population, period.
sourcestringData source, shown as "Source: ...".
notestringMethod notes or caveats.
heightnumber | stringCSS height of the plot. Default 360.
aspectnumberWidth / height. Overrides height.
highlightstring | string[]The entity (or entities) the title is about. Every other series is drawn in grey.
annotationsAnnotation[]Reference lines, shaded bands and callouts, in data coordinates.
formatFormatSpecHow to print values: "compact", "percent", "currency:USD", "{value} kg", Intl options, or a function.
legendbooleanShow the legend. Default: shown when there are two or more series.
selectboolean | stringMake marks clickable to filter. Inside <InsightData> the selection filters every other chart. Pass a field name, or true to use the chart's category field.
onSelect(values: string[], field: string) => voidCalled with the selected values whenever the selection changes.
optionEChartsOption | ((option: EChartsOption, ctx: BuildContext) => EChartsOption)Deep-merged over the generated ECharts option, or a function that receives and returns it. Use it for ECharts settings no prop covers.
themeThemeInputA theme, or a partial set of tokens merged over the surrounding theme, for this chart only.
modeModeInput"auto" (default) follows the page, "system" follows the OS, or force "light" / "dark".
rendererRendererInput"auto" (default) uses SVG for light charts and canvas for heavy ones.
animatebooleanSet false to disable animation. Reduced-motion preferences are always respected.
lazybooleanMount the chart only when it scrolls near the viewport. Default true.
groupstringLink tooltips with other charts sharing this group id.
exportableboolean | ExportFormat[]Show an export menu: true or a list of formats from png, jpeg, svg, pdf, csv, json.
tablebooleanShow a collapsible "View data" table under the chart.
altstringAccessible description: the chart type and measures, then the main pattern and the notable values.
idstringStable id for this chart's selection in the shared store.
onEventsRecord<string, ChartEventHandler>ECharts event handlers, e.g. { click: (params, chart) => {} }. Prefix a name with zr: to bind to the canvas itself.
onReady(chart: EChartsInstance) => voidCalled with the ECharts instance once it is created.
classNamestringClass name for the outer <figure>.
styleCSSPropertiesInline style for the outer <figure>.