Compiling Vega-Lite to Vega

If you would rather compile your Vega-Lite specifications into Vega, you can use Vega-Lite’s included javascript compiler or one of several bundled command line utilities.

First install Vega-Lite using npm (npm install vega-lite) or by downloading the latest release. (For the latter, you will also have to download Vega and D3.)

Using Javascript

If you want access to the compiled Vega spec from a Javascript program, you can compile your Vega-Lite spec using the vl.compile function.

var vgSpec = vl.compile(vlSpec).spec;

By default, warnings and errors are printed to the JavaScript console. To customize how errors and warnings are handled, you can pass a customize logger to the compile function.

var vgSpec = vl.compile(vlSpec, logger).spec;

A custom logger should implement the following interface:

interface LoggerInterface {
  level: (_: number) => number | LoggerInterface;
  warn(...args: any[]): LoggerInterface;
  info(...args: any[]): LoggerInterface;
  debug(...args: any[]): LoggerInterface;
}

From the Command Line

If you want to compile your Vega-Lite specs from the command line, we provide a set of scripts which make it easy to go from Vega-Lite to Vega, SVG, or PNG. These scripts are vl2vg, vl2svg, and vl2png respectively.

Each script simply accepts your Vega-Lite specification as its first argument.

vl2svg vlSpec