| title | Spec reference |
|---|---|
| description | The VizSpec union, the spec builder functions, and a one-line index of every reference page. |
| section | spec |
| slug | overview |
| order | 1 |
Every OpenChart visualization is one JSON object, a VizSpec. The reference pages list each spec type field by field, with types and defaults checked against the TypeScript source in packages/core/src/types/. Use them to look up an exact name or default; the Building blocks pages teach the same fields with charts.
See it: Anatomy of a spec builds a spec one block at a time.
All types are importable from @opendata-ai/openchart-core or from the convenience re-exports in @opendata-ai/openchart-react, @opendata-ai/openchart-vue, @opendata-ai/openchart-svelte, and @opendata-ai/openchart-engine.
- ChartSpec: a chart with one mark, its top-level fields and mark properties, plus
a11yandframe. - LayerSpec: several chart specs on shared axes, and what each layer inherits.
- Encoding: the channels, field types, aggregates, axes and scales, and faceting into small multiples.
- Marks: the channels each mark takes, a complete spec for each common chart, and canvas mark mode.
- Chrome, labels and legends: title, subtitle, source, byline and footer, value labels, endpoint labels and the legend.
- Transforms: filter, bin, calculate, timeUnit, aggregate, joinaggregate, fold, window and density.
- Annotations: text callouts, ranges and reference lines.
- Animation: presets, entrance and update phases, and data-update transitions.
- Theme:
ThemeConfigoverrides and theDarkModesetting. - TableSpec: data tables,
ColumnConfigand the column visual types. - GraphSpec: network charts and the
Graphcomponent. - SankeySpec: flow diagrams.
- TileMapSpec: US state tile grids.
- GeoMapSpec: choropleth and symbol maps.
- BarListSpec: ranked bar lists.
- Authoring and reader APIs: field metadata, reader identity, diagnostics and callout limits for editing and reading apps.
- Color accessibility helpers: color-vision simulation and perceptual palette distinguishability checks.
- Vanilla API: the
create*mount functions,MountOptions,ChartInstanceand the lifecycle. - React, Vue and Svelte: components, props, hooks or composables, and server rendering.
- Events: every handler and payload, interaction modes and edit persistence.
- Export API: SVG, PNG, JPG, CSV and animated GIF export.
- Table state: controlled and uncontrolled sort, search and pagination.
- Theming tokens:
ThemeConfigfields and the CSS custom properties behind them. - Design system: the default palette, type scale, spacing, mark defaults, motion and presets.
- JSON Schema and llms.txt: the published schema,
validateSpecand its error codes, the llms.txt exports and the agent skill.
The top-level type is a discriminated union on the type field:
type VizSpec =
| ChartSpec
| LayerSpec
| TableSpec
| GraphSpec
| SankeySpec
| TileMapSpec
| GeoMapSpec
| BarListSpec;Use type to select which spec shape you're building:
- Chart types (
line,area,bar,column,pie,donut,dot,scatter) produce aChartSpec tableproduces aTableSpecgraphproduces aGraphSpecsankeyproduces aSankeySpectilemapproduces aTileMapSpecmapproduces aGeoMapSpecbarlistproduces aBarListSpec
Type guards are available: isChartSpec(spec), isTableSpec(spec), isGraphSpec(spec), isSankeySpec(spec), isTileMapSpec(spec), isGeoMapSpec(spec), isBarListSpec(spec).
Helper functions that reduce boilerplate. Source: core/src/helpers/spec-builders.ts.
All builders accept field names as strings (auto-infer type from data) or full EncodingChannel objects (when you need to customize type, aggregate, axis, or scale).
| Builder | Signature | Produces |
|---|---|---|
lineChart |
(data, x, y, options?) |
ChartSpec with mark: 'line' |
areaChart |
(data, x, y, options?) |
ChartSpec with mark: 'area' |
barChart |
(data, category, value, options?) |
ChartSpec with mark: 'bar'. category -> y, value -> x |
columnChart |
(data, x, y, options?) |
ChartSpec with mark: 'bar'. x nominal, y quantitative |
pieChart |
(data, category, value, options?) |
ChartSpec with mark: 'arc'. category -> color, value -> y |
donutChart |
(data, category, value, options?) |
ChartSpec with mark: { type: 'arc', innerRadius: 40 }. category -> color, value -> y |
dotChart |
(data, x, y, options?) |
ChartSpec with mark: 'circle' |
scatterChart |
(data, x, y, options?) |
ChartSpec with mark: 'point' |
dataTable |
(data, options?) |
TableSpec. Auto-generates columns from data keys if none provided. |
| Field | Type | Description |
|---|---|---|
color |
FieldRef |
Color encoding for series differentiation. |
size |
FieldRef |
Size encoding (bubble charts). |
chrome |
Chrome |
Editorial chrome. |
annotations |
Annotation[] |
Annotations. |
responsive |
boolean |
Responsive behavior. |
theme |
ThemeConfig |
Theme overrides. |
watermark |
boolean |
Whether to show the OpenChart watermark. Mount/compile options take precedence over the spec; defaults to true. |
FieldRef is string | EncodingChannel. When a string is provided, inferFieldType() uses the shared builder/compiler inference: sample up to 50 rows, ignore nulls, and require more than 80% agreement. Numeric strings are considered before dates, so a column of '2020' values is quantitative. Set the channel type explicitly when years should be ordinal or temporal.
import { lineChart } from "@opendata-ai/openchart-core";
const spec = lineChart(data, "date", "revenue", {
color: "region",
chrome: { title: "Revenue trend" },
annotations: [{ type: "refline", y: 50000, label: "Target" }],
});