Skip to content
OpenChart

Introduction

What OpenChart makes, shown as published graphics, and how these docs are organized.

OpenChart draws charts, tables, graphs and maps from a JSON spec. A spec holds the data, the mark and encoding, and the text around the chart, and the library handles scales, label placement, accessibility and layout at any width. One spec renders in React, Vue, Svelte or plain JavaScript, and to static SVG for pages that run no script.

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);

Under each figure, Code opens the spec and the React, Vue, Svelte and vanilla JavaScript that draws it.

Indicators for twelve economies. This chart is drawn in the browser.

Indicators for twelve economies. Source: World Bank WDI, OWID (PPP GDP), WHO Global Health Observatory.
{
  "type": "table",
  "data": [
    {
      "code": "IN",
      "country": "India",
      "population": 1438069596,
      "gdpPerCapita": 9818,
      "lifeExpectancy": 68.3
    },
    {
      "code": "CN",
      "country": "China",
      "population": 1410710000,
      "gdpPerCapita": 23846,
      "lifeExpectancy": 76.1
    },
    {
      "code": "US",
      "country": "United States",
      "population": 336806231,
      "gdpPerCapita": 75489,
      "lifeExpectancy": 79.2
    },
    {
      "code": "ID",
      "country": "Indonesia",
      "population": 281190067,
      "gdpPerCapita": 14470,
      "lifeExpectancy": 69
    },
    {
      "code": "BR",
      "country": "Brazil",
      "population": 211140729,
      "gdpPerCapita": 19652,
      "lifeExpectancy": 75.3
    },
    {
      "code": "MX",
      "country": "Mexico",
      "population": 129739759,
      "gdpPerCapita": 22040,
      "lifeExpectancy": 76.9
    },
    {
      "code": "JP",
      "country": "Japan",
      "population": 124516650,
      "gdpPerCapita": 46107,
      "lifeExpectancy": 83.6
    },
    {
      "code": "DE",
      "country": "Germany",
      "population": 83287273,
      "gdpPerCapita": 63676,
      "lifeExpectancy": 80.8
    },
    {
      "code": "GB",
      "country": "United Kingdom",
      "population": 68492000,
      "gdpPerCapita": 53139,
      "lifeExpectancy": 81.4
    },
    {
      "code": "FR",
      "country": "France",
      "population": 68372286,
      "gdpPerCapita": 54799,
      "lifeExpectancy": 82.4
    },
    {
      "code": "KR",
      "country": "South Korea",
      "population": 51712619,
      "gdpPerCapita": 55071,
      "lifeExpectancy": 81.9
    },
    {
      "code": "CA",
      "country": "Canada",
      "population": 40083484,
      "gdpPerCapita": 58321,
      "lifeExpectancy": 82.2
    }
  ],
  "columns": [
    {
      "key": "country",
      "label": "Country",
      "sortable": true
    },
    {
      "key": "population",
      "label": "Population",
      "format": ",.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "gdpPerCapita",
      "label": "GDP/capita (PPP)",
      "format": "$,.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "lifeExpectancy",
      "label": "Life exp.",
      "format": ".1f",
      "sortable": true,
      "align": "right"
    }
  ],
  "chrome": {
    "title": "Twelve of the world's largest economies",
    "subtitle": "Population, income and longevity for the largest economies"
  },
  "search": true,
  "pagination": {
    "pageSize": 8
  }
}
import { DataTable } from "@opendata-ai/openchart-react";
import type { TableSpec } 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: TableSpec = {
  data,
  "type": "table",
  "columns": [
    {
      "key": "country",
      "label": "Country",
      "sortable": true
    },
    {
      "key": "population",
      "label": "Population",
      "format": ",.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "gdpPerCapita",
      "label": "GDP/capita (PPP)",
      "format": "$,.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "lifeExpectancy",
      "label": "Life exp.",
      "format": ".1f",
      "sortable": true,
      "align": "right"
    }
  ],
  "chrome": {
    "title": "Twelve of the world's largest economies",
    "subtitle": "Population, income and longevity for the largest economies"
  },
  "search": true,
  "pagination": {
    "pageSize": 8
  }
};

export function Example() {
  return <DataTable spec={spec} />;
}
<script setup lang="ts">
import { DataTable } from "@opendata-ai/openchart-vue";
import type { TableSpec } 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: TableSpec = {
  data,
  "type": "table",
  "columns": [
    {
      "key": "country",
      "label": "Country",
      "sortable": true
    },
    {
      "key": "population",
      "label": "Population",
      "format": ",.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "gdpPerCapita",
      "label": "GDP/capita (PPP)",
      "format": "$,.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "lifeExpectancy",
      "label": "Life exp.",
      "format": ".1f",
      "sortable": true,
      "align": "right"
    }
  ],
  "chrome": {
    "title": "Twelve of the world's largest economies",
    "subtitle": "Population, income and longevity for the largest economies"
  },
  "search": true,
  "pagination": {
    "pageSize": 8
  }
};
</script>

<template>
  <DataTable :spec="spec" />
</template>
<script lang="ts">
import { DataTable } from "@opendata-ai/openchart-svelte";
import type { TableSpec } 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: TableSpec = {
  data,
  "type": "table",
  "columns": [
    {
      "key": "country",
      "label": "Country",
      "sortable": true
    },
    {
      "key": "population",
      "label": "Population",
      "format": ",.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "gdpPerCapita",
      "label": "GDP/capita (PPP)",
      "format": "$,.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "lifeExpectancy",
      "label": "Life exp.",
      "format": ".1f",
      "sortable": true,
      "align": "right"
    }
  ],
  "chrome": {
    "title": "Twelve of the world's largest economies",
    "subtitle": "Population, income and longevity for the largest economies"
  },
  "search": true,
  "pagination": {
    "pageSize": 8
  }
};
</script>

<DataTable {spec} />
import { createTable } from "@opendata-ai/openchart-vanilla";
import type { TableSpec } 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: TableSpec = {
  data,
  "type": "table",
  "columns": [
    {
      "key": "country",
      "label": "Country",
      "sortable": true
    },
    {
      "key": "population",
      "label": "Population",
      "format": ",.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "gdpPerCapita",
      "label": "GDP/capita (PPP)",
      "format": "$,.0f",
      "sortable": true,
      "align": "right"
    },
    {
      "key": "lifeExpectancy",
      "label": "Life exp.",
      "format": ".1f",
      "sortable": true,
      "align": "right"
    }
  ],
  "chrome": {
    "title": "Twelve of the world's largest economies",
    "subtitle": "Population, income and longevity for the largest economies"
  },
  "search": true,
  "pagination": {
    "pageSize": 8
  }
};

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

A table spec lists columns instead of encodings. This one sorts, searches and pages.

Unemployment is highest in DC and lowest in SouthDakotaUnemployment rate by state (%)3.04.05.0Unemployment rate (%)Unemployment is highest in DC and lowest in SouthDakotaUnemployment rate by state (%)3.04.05.0Unemployment rate (%)
Unemployment rate by state. Source: Bureau of Labor Statistics, Local Area Unemployment Statistics; geography: US Census Bureau via us-atlas.
{
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "data": [
    {
      "id": "01",
      "rate": 2.7
    },
    {
      "id": "02",
      "rate": 4.8
    },
    {
      "id": "04",
      "rate": 4.7
    },
    {
      "id": "05",
      "rate": 4.2
    },
    {
      "id": "06",
      "rate": 5.3
    },
    {
      "id": "08",
      "rate": 3.8
    },
    // … 45 more rows; Copy includes them
  ],
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
}
import { GeoMap } from "@opendata-ai/openchart-react";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};

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

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

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};
</script>

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

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

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};
</script>

<GeoMap {spec} />
import { createGeoMap } from "@opendata-ai/openchart-vanilla";
import type { GeoMapSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: GeoMapSpec = {
  data,
  "type": "map",
  "geo": {
    "features": {/* TopoJSON, 181 arcs; Copy includes it */},
    "projection": "albersUsa"
  },
  "encoding": {
    "key": {
      "field": "id",
      "type": "nominal"
    },
    "color": {
      "field": "rate",
      "type": "quantitative",
      "format": ".1f",
      "title": "Unemployment rate (%)"
    }
  },
  "chrome": {
    "title": "Unemployment is highest in DC and lowest in South Dakota",
    "subtitle": "Unemployment rate by state (%)"
  }
};

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

A map spec joins each region’s shape to a value by key, here a state’s FIPS code.

How the docs are organized

Guides take you from install to a working chart. They cover the four framework packages, rendering static SVG at build time, having a language model write specs, recipes for dashboards and for ranking and change, and the upgrade notes for versions 8 and 9.

Visualizations has one page per chart type, table, graph and map, filed by what the reader should see: comparison, change over time, part to whole, distribution, correlation, flow, maps, tables and composition. Each page shows live examples.

Building blocks explain the parts of a spec one at a time: encoding, scales and axes, the title and annotations around a chart, themes, motion, interaction and export.

Reference lists every spec field, the API of each framework package, the theming tokens, and the JSON Schema and llms.txt files for tools and agents.