Skip to main content
The builders — createSpec, pipe, geom.*, scale.*, config — are a convenience. What they produce is a plain, immutable object of objects, arrays, strings, numbers and booleans. A spec holds no functions, class instances or DOM references, so it round-trips through JSON.stringify / JSON.parse unchanged. You can store a spec in a database, send it over the wire, generate it from another language, or write one by hand.

The builders only assemble an object

pipe(...) and the geom.* / scale.* / config helpers assemble and merge a plain object. This call:
produces exactly this object — and JSON.stringify(spec) gives you exactly this JSON (fields left undefined drop out):
You could paste that JSON into your source and pass it to GraphProvider as spec, with no builder in sight. What the builders add is types: autocomplete for aesthetics, options and params, and a type check on the shape. Defaults are filled in at compile time either way.

Every top-level key

createSpec seeds six keys — mapping, layers, scales, transforms, highlights and config — so they are present even when empty. The other three appear only once something is piped in:

A styled spec is still JSON

The stylesheet is the largest thing a spec carries, and it round-trips like the rest. A token('brand') reference is a plain object the compile stage inlines. A light/dark color pair is a plain object the renderer picks from at read time. Neither needs a function:

Writing the JSON by hand

Two things to know before you do. A layer’s aesthetic override is called aes on the builder and mapping in the object: geom.line({ aes: { y: 'profit' } }) serializes as { "type": "layer", "geom": "line", "mapping": { "y": "profit" } }. A spec that uses a plugin geom, stat or transform still serializes: a custom layer is just { "geom": "candlestick", "params": { … } }. The plugin itself is code. It reaches the chart through the plugins array on GraphProvider, not through the spec. Store the spec; ship the plugins with your app.

Next

  • How a chart is built — the compile → render pipeline that consumes a spec
  • Data structure — the table a spec references by column name
  • Extending — custom geoms, stats and transforms, and the plugins they ship in