Skip to content
OpenChart

Line

Trace one or more series across a continuous axis, then annotate, label the line ends, focus a series, change the curve, format dates and switch to a log scale.

A line chart shows how a value changes along a continuous axis, usually time. The reader follows the slope: a steep stretch is fast change, a flat one is stability. Several series can share one plot when each has its own color.

Use columns when you have a handful of separate periods and the reader should compare each value. Use an area chart when the size of the total matters more than the slope, and a slope chart when only two moments matter.

A basic line chart

Set mark to "line", put the date on x with type: "temporal" and the number on y. Here a text annotation with a connector marks the peak, and a dashed refline marks a target.

2019202020212022202320240.02.04.06.08.0CPI (year-over-year %)Peak: 8.5%Fed 2% targetUS inflation peaked at 8.5% in 2022 and fellbelow 3% in mid-2024US consumer price index, year-over-year % change, quarterly 2019-20242019202020212022202320240.02.04.06.08.0CPI (year-over-year %)Peak: 8.5%Fed 2% targetUS inflation peaked at 8.5% in 2022 and fellbelow 3% in mid-2024US consumer price index, year-over-year % change, quarterly 2019-2024
US inflation. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    // … 18 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year %)",
        "format": ".1f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -20
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed 2% target",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "US inflation peaked at 8.5% in 2022 and fell below 3% in mid-2024",
    "subtitle": "US consumer price index, year-over-year % change, quarterly 2019-2024"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year %)",
        "format": ".1f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -20
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed 2% target",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "US inflation peaked at 8.5% in 2022 and fell below 3% in mid-2024",
    "subtitle": "US consumer price index, year-over-year % change, quarterly 2019-2024"
  }
};

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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year %)",
        "format": ".1f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -20
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed 2% target",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "US inflation peaked at 8.5% in 2022 and fell below 3% in mid-2024",
    "subtitle": "US consumer price index, year-over-year % change, quarterly 2019-2024"
  }
};
</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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year %)",
        "format": ".1f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -20
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed 2% target",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "US inflation peaked at 8.5% in 2022 and fell below 3% in mid-2024",
    "subtitle": "US consumer price index, year-over-year % change, quarterly 2019-2024"
  }
};
</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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year %)",
        "format": ".1f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -20
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed 2% target",
      "style": "dashed",
      "stroke": "#64748b",
      "strokeWidth": 1
    }
  ],
  "chrome": {
    "title": "US inflation peaked at 8.5% in 2022 and fell below 3% in mid-2024",
    "subtitle": "US consumer price index, year-over-year % change, quarterly 2019-2024"
  }
};

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

Several series

Add a color channel to draw one line per value of a field. With a handful of series, endpointLabels names each line at its right end, so the reader does not have to match colors to a legend. A range annotation shades a stretch of the x axis, and a refline at y: 0 marks the baseline.

2018202020222024−6−4−2+0+2+4+6+8GDP growth (%)PandemicUnited States+2.8Euro Area+0.8China+5.0All three economies slowed or shrank in 2020and rebounded in 2021Annual real GDP growth rate, 2018-20242018202020222024−6−4−2+0+2+4+6+8GDP growth (%)PandemicUnited States+2.8Euro Area+0.8China+5.0All three economies slowed or shrank in 2020and rebounded in 2021Annual real GDP growth rate, 2018-2024
GDP growth in three economies. Source: IMF World Economic Outlook, World Bank.
{
  "mark": "line",
  "data": [
    {
      "date": "2018-01-01",
      "gdp": 3,
      "country": "United States"
    },
    {
      "date": "2019-01-01",
      "gdp": 2.5,
      "country": "United States"
    },
    {
      "date": "2020-01-01",
      "gdp": -2.2,
      "country": "United States"
    },
    {
      "date": "2021-01-01",
      "gdp": 6.1,
      "country": "United States"
    },
    {
      "date": "2022-01-01",
      "gdp": 2.5,
      "country": "United States"
    },
    {
      "date": "2023-01-01",
      "gdp": 2.9,
      "country": "United States"
    },
    // … 15 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 4
      }
    },
    "y": {
      "field": "gdp",
      "type": "quantitative",
      "axis": {
        "title": "GDP growth (%)",
        "format": "+.0f",
        "grid": true
      }
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "stroke": "#94a3b8",
      "strokeWidth": 1
    },
    {
      "type": "range",
      "x1": "2019-09-01",
      "x2": "2020-06-01",
      "label": "Pandemic",
      "fill": "#dc2626",
      "opacity": 0.06
    }
  ],
  "endpointLabels": {
    "format": "+.1f"
  },
  "chrome": {
    "title": "All three economies slowed or shrank in 2020 and rebounded in 2021",
    "subtitle": "Annual real GDP growth rate, 2018-2024"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 4
      }
    },
    "y": {
      "field": "gdp",
      "type": "quantitative",
      "axis": {
        "title": "GDP growth (%)",
        "format": "+.0f",
        "grid": true
      }
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "stroke": "#94a3b8",
      "strokeWidth": 1
    },
    {
      "type": "range",
      "x1": "2019-09-01",
      "x2": "2020-06-01",
      "label": "Pandemic",
      "fill": "#dc2626",
      "opacity": 0.06
    }
  ],
  "endpointLabels": {
    "format": "+.1f"
  },
  "chrome": {
    "title": "All three economies slowed or shrank in 2020 and rebounded in 2021",
    "subtitle": "Annual real GDP growth rate, 2018-2024"
  }
};

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 = [/* 21 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 4
      }
    },
    "y": {
      "field": "gdp",
      "type": "quantitative",
      "axis": {
        "title": "GDP growth (%)",
        "format": "+.0f",
        "grid": true
      }
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "stroke": "#94a3b8",
      "strokeWidth": 1
    },
    {
      "type": "range",
      "x1": "2019-09-01",
      "x2": "2020-06-01",
      "label": "Pandemic",
      "fill": "#dc2626",
      "opacity": 0.06
    }
  ],
  "endpointLabels": {
    "format": "+.1f"
  },
  "chrome": {
    "title": "All three economies slowed or shrank in 2020 and rebounded in 2021",
    "subtitle": "Annual real GDP growth rate, 2018-2024"
  }
};
</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 = [/* 21 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 4
      }
    },
    "y": {
      "field": "gdp",
      "type": "quantitative",
      "axis": {
        "title": "GDP growth (%)",
        "format": "+.0f",
        "grid": true
      }
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "stroke": "#94a3b8",
      "strokeWidth": 1
    },
    {
      "type": "range",
      "x1": "2019-09-01",
      "x2": "2020-06-01",
      "label": "Pandemic",
      "fill": "#dc2626",
      "opacity": 0.06
    }
  ],
  "endpointLabels": {
    "format": "+.1f"
  },
  "chrome": {
    "title": "All three economies slowed or shrank in 2020 and rebounded in 2021",
    "subtitle": "Annual real GDP growth rate, 2018-2024"
  }
};
</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 = [/* 21 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 4
      }
    },
    "y": {
      "field": "gdp",
      "type": "quantitative",
      "axis": {
        "title": "GDP growth (%)",
        "format": "+.0f",
        "grid": true
      }
    },
    "color": {
      "field": "country",
      "type": "nominal"
    }
  },
  "annotations": [
    {
      "type": "refline",
      "y": 0,
      "style": "solid",
      "stroke": "#94a3b8",
      "strokeWidth": 1
    },
    {
      "type": "range",
      "x1": "2019-09-01",
      "x2": "2020-06-01",
      "label": "Pandemic",
      "fill": "#dc2626",
      "opacity": 0.06
    }
  ],
  "endpointLabels": {
    "format": "+.1f"
  },
  "chrome": {
    "title": "All three economies slowed or shrank in 2020 and rebounded in 2021",
    "subtitle": "Annual real GDP growth rate, 2018-2024"
  }
};

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

Focusing one series

To focus one series, put an explicit scale on the color channel that maps that company to the accent and the others to grey. seriesStyles thickens the focus line, and legend: { show: false } drops the legend because endpointLabels with content: "label" already names every line.

Big tech revenue with one company in focus. This chart is drawn in the browser.

Big tech revenue with one company in focus. Source: Company annual reports (SEC 10-K filings).
{
  "mark": "line",
  "data": [
    {
      "year": "2019-01-01",
      "revenue": 280,
      "company": "Amazon"
    },
    {
      "year": "2020-01-01",
      "revenue": 386,
      "company": "Amazon"
    },
    {
      "year": "2021-01-01",
      "revenue": 470,
      "company": "Amazon"
    },
    {
      "year": "2022-01-01",
      "revenue": 514,
      "company": "Amazon"
    },
    {
      "year": "2023-01-01",
      "revenue": 574,
      "company": "Amazon"
    },
    {
      "year": "2024-01-01",
      "revenue": 638,
      "company": "Amazon"
    },
    // … 24 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal",
      "scale": {
        "domain": [
          "Amazon",
          "Apple",
          "Alphabet",
          "Microsoft",
          "Meta"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "legend": {
    "show": false
  },
  "endpointLabels": {
    "content": "label",
    "showMarker": true
  },
  "seriesStyles": {
    "Amazon": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Amazon's revenue lead over the rest of big tech widened every year",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal",
      "scale": {
        "domain": [
          "Amazon",
          "Apple",
          "Alphabet",
          "Microsoft",
          "Meta"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "legend": {
    "show": false
  },
  "endpointLabels": {
    "content": "label",
    "showMarker": true
  },
  "seriesStyles": {
    "Amazon": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Amazon's revenue lead over the rest of big tech widened every year",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};

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 = [/* 30 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal",
      "scale": {
        "domain": [
          "Amazon",
          "Apple",
          "Alphabet",
          "Microsoft",
          "Meta"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "legend": {
    "show": false
  },
  "endpointLabels": {
    "content": "label",
    "showMarker": true
  },
  "seriesStyles": {
    "Amazon": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Amazon's revenue lead over the rest of big tech widened every year",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};
</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 = [/* 30 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal",
      "scale": {
        "domain": [
          "Amazon",
          "Apple",
          "Alphabet",
          "Microsoft",
          "Meta"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "legend": {
    "show": false
  },
  "endpointLabels": {
    "content": "label",
    "showMarker": true
  },
  "seriesStyles": {
    "Amazon": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Amazon's revenue lead over the rest of big tech widened every year",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};
</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 = [/* 30 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "line",
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "revenue",
      "type": "quantitative",
      "axis": {
        "title": "Annual revenue ($B)",
        "format": ",.0f",
        "grid": true
      }
    },
    "color": {
      "field": "company",
      "type": "nominal",
      "scale": {
        "domain": [
          "Amazon",
          "Apple",
          "Alphabet",
          "Microsoft",
          "Meta"
        ],
        "range": [
          "#0e7490",
          "#7a858f",
          "#7a858f",
          "#7a858f",
          "#7a858f"
        ]
      }
    }
  },
  "legend": {
    "show": false
  },
  "endpointLabels": {
    "content": "label",
    "showMarker": true
  },
  "seriesStyles": {
    "Amazon": {
      "strokeWidth": 3
    }
  },
  "chrome": {
    "title": "Amazon's revenue lead over the rest of big tech widened every year",
    "subtitle": "Annual revenue by company, 2019-2024 (billions USD)"
  }
};

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

Step lines

interpolate on the mark sets the curve between points. The default, "monotone", draws a smooth curve through every point that never overshoots between them. "linear" draws straight segments. "step-after" holds each value until the next point, which suits a quantity that changes at discrete moments; "step" switches halfway between points. "natural" draws a cubic spline through every point, which can overshoot. point: true draws a dot at every observation.

JanMarMayJulSepNov5101520Temperature (°C)A step-after line holds each value until thenext pointMonthly temperature with interpolate: "step-after"JanMarMayJulSepNov5101520Temperature (°C)A step-after line holds each value until thenext pointMonthly temperature with interpolate: "step-after"
Monthly temperature as a step-after line. Source: Illustrative data.
{
  "mark": {
    "type": "line",
    "interpolate": "step-after",
    "point": true,
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "data": [
    {
      "month": "Jan",
      "temp": 2.1
    },
    {
      "month": "Feb",
      "temp": 3.5
    },
    {
      "month": "Mar",
      "temp": 7.8
    },
    {
      "month": "Apr",
      "temp": 12.4
    },
    {
      "month": "May",
      "temp": 17.2
    },
    {
      "month": "Jun",
      "temp": 21
    },
    {
      "month": "Jul",
      "temp": 23.5
    },
    {
      "month": "Aug",
      "temp": 22.8
    },
    {
      "month": "Sep",
      "temp": 18.6
    },
    {
      "month": "Oct",
      "temp": 12.9
    },
    {
      "month": "Nov",
      "temp": 7.1
    },
    {
      "month": "Dec",
      "temp": 3.2
    }
  ],
  "encoding": {
    "x": {
      "field": "month",
      "type": "ordinal"
    },
    "y": {
      "field": "temp",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)",
        "grid": true,
        "tickCount": 5
      }
    }
  },
  "chrome": {
    "title": "A step-after line holds each value until the next point",
    "subtitle": "Monthly temperature with interpolate: \"step-after\""
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "step-after",
    "point": true,
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "month",
      "type": "ordinal"
    },
    "y": {
      "field": "temp",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)",
        "grid": true,
        "tickCount": 5
      }
    }
  },
  "chrome": {
    "title": "A step-after line holds each value until the next point",
    "subtitle": "Monthly temperature with interpolate: \"step-after\""
  }
};

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 = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "step-after",
    "point": true,
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "month",
      "type": "ordinal"
    },
    "y": {
      "field": "temp",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)",
        "grid": true,
        "tickCount": 5
      }
    }
  },
  "chrome": {
    "title": "A step-after line holds each value until the next point",
    "subtitle": "Monthly temperature with interpolate: \"step-after\""
  }
};
</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 = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "step-after",
    "point": true,
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "month",
      "type": "ordinal"
    },
    "y": {
      "field": "temp",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)",
        "grid": true,
        "tickCount": 5
      }
    }
  },
  "chrome": {
    "title": "A step-after line holds each value until the next point",
    "subtitle": "Monthly temperature with interpolate: \"step-after\""
  }
};
</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 = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "interpolate": "step-after",
    "point": true,
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "month",
      "type": "ordinal"
    },
    "y": {
      "field": "temp",
      "type": "quantitative",
      "axis": {
        "title": "Temperature (°C)",
        "grid": true,
        "tickCount": 5
      }
    }
  },
  "chrome": {
    "title": "A step-after line holds each value until the next point",
    "subtitle": "Monthly temperature with interpolate: \"step-after\""
  }
};

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

Date ticks

axis.format on a temporal channel takes a d3-time-format string, here "%b '%y" for ticks like “Jan ’19”, and tickCount suggests how many ticks to draw. The y axis uses a d3-format string: the data is stored as fractions, so ".0%" prints 8% for 0.08.

Jan '19Jan '20Jan '21Jan '22Jan '23Jan '240%2%4%6%8%CPI (year-over-year)A custom tick format keeps a dense time axisreadableQuarterly 2019-2024, ticks formatted as month and two-digit yearJan '19Jan '20Jan '21Jan '22Jan '23Jan '240%2%4%6%8%CPI (year-over-year)A custom tick format keeps a dense time axisreadableQuarterly 2019-2024, ticks formatted as month and two-digit year
US inflation with compact date ticks. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "data": [
    {
      "date": "2019-01-01",
      "rate": 0.016
    },
    {
      "date": "2019-04-01",
      "rate": 0.02
    },
    {
      "date": "2019-07-01",
      "rate": 0.018000000000000002
    },
    {
      "date": "2019-10-01",
      "rate": 0.018000000000000002
    },
    {
      "date": "2020-01-01",
      "rate": 0.025
    },
    {
      "date": "2020-04-01",
      "rate": 0.003
    },
    // … 18 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%b '%y",
        "tickCount": 8
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year)",
        "format": ".0%",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "A custom tick format keeps a dense time axis readable",
    "subtitle": "Quarterly 2019-2024, ticks formatted as month and two-digit year"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%b '%y",
        "tickCount": 8
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year)",
        "format": ".0%",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "A custom tick format keeps a dense time axis readable",
    "subtitle": "Quarterly 2019-2024, ticks formatted as month and two-digit year"
  }
};

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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%b '%y",
        "tickCount": 8
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year)",
        "format": ".0%",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "A custom tick format keeps a dense time axis readable",
    "subtitle": "Quarterly 2019-2024, ticks formatted as month and two-digit year"
  }
};
</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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%b '%y",
        "tickCount": 8
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year)",
        "format": ".0%",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "A custom tick format keeps a dense time axis readable",
    "subtitle": "Quarterly 2019-2024, ticks formatted as month and two-digit year"
  }
};
</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 = [/* 24 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "format": "%b '%y",
        "tickCount": 8
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "CPI (year-over-year)",
        "format": ".0%",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "A custom tick format keeps a dense time axis readable",
    "subtitle": "Quarterly 2019-2024, ticks formatted as month and two-digit year"
  }
};

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

Log scale

scale: { type: "log" } on the y channel spaces values by ratio. A series that grows by a similar percentage each year plots as a near-straight line, so a change in the growth rate stands out where a linear axis would bury it.

20162018202020222024110100Cumulative EV fleet (millions, log)On a log scale, steady growth plots as astraight lineCumulative global electric car fleet, 2015-2024 (BEV + PHEV)20162018202020222024110100Cumulative EV fleet (millions, log)On a log scale, steady growth plots as astraight lineCumulative global electric car fleet, 2015-2024 (BEV + PHEV)
Electric car fleet on a log scale. Source: IEA Global EV Outlook 2025.
{
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "data": [
    {
      "year": "2015-01-01",
      "fleet": 1.3
    },
    {
      "year": "2016-01-01",
      "fleet": 2.1
    },
    {
      "year": "2017-01-01",
      "fleet": 3.2
    },
    {
      "year": "2018-01-01",
      "fleet": 5.4
    },
    {
      "year": "2019-01-01",
      "fleet": 7.5
    },
    {
      "year": "2020-01-01",
      "fleet": 10.5
    },
    {
      "year": "2021-01-01",
      "fleet": 17.1
    },
    {
      "year": "2022-01-01",
      "fleet": 27
    },
    {
      "year": "2023-01-01",
      "fleet": 41
    },
    {
      "year": "2024-01-01",
      "fleet": 58
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "Cumulative EV fleet (millions, log)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "On a log scale, steady growth plots as a straight line",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "Cumulative EV fleet (millions, log)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "On a log scale, steady growth plots as a straight line",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};

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 = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "Cumulative EV fleet (millions, log)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "On a log scale, steady growth plots as a straight line",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};
</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 = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "Cumulative EV fleet (millions, log)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "On a log scale, steady growth plots as a straight line",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};
</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 = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "stroke": "#0e7490",
    "strokeWidth": 2,
    "point": true
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "tickCount": 5
      }
    },
    "y": {
      "field": "fleet",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "Cumulative EV fleet (millions, log)",
        "format": ",.0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "On a log scale, steady growth plots as a straight line",
    "subtitle": "Cumulative global electric car fleet, 2015-2024 (BEV + PHEV)"
  }
};

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

Fields that matter

Field What it does
mark "line", or an object such as { type: "line", interpolate: "step-after", point: true } to set the curve, point markers and stroke.
encoding.x The horizontal position. Use type: "temporal" for dates and "ordinal" for named periods.
encoding.y The value. scale.type: "log" switches to a log axis.
encoding.color One line per value of this field. scale.domain and scale.range pin colors to series.
endpointLabels Names each line at its end. content picks the label text.
seriesStyles Per-series overrides, keyed by the series name, such as a thicker stroke.
annotations text, refline and range marks placed in data coordinates.
axis.format A d3-format or d3-time-format string for tick labels.
  • Area fills under the line.
  • Slope and bump compare two moments or rank over time.
  • Sparkline shrinks a line to fit beside a number.
  • Column compares values across a few periods.
  • Marks reference lists the channels and options each mark type takes.