The Vega-Lite API (version 6.0.0) provides a JavaScript fluent API for programmatically constructing Vega-Lite JSON specifications. It serves as a high-level grammar for visual analysis, enabling developers to define interactive visualizations in a more structured and code-centric manner than direct JSON manipulation. The package tracks the major version of Vega-Lite, ensuring compatibility with the underlying visualization grammar; v6.x of this API is compatible with Vega-Lite v6.x. It differentiates itself by offering a declarative chaining syntax that simplifies complex specification creation, particularly beneficial in environments like Observable notebooks or browser-based applications where dynamic chart generation is common. The API is actively maintained with releases tied to Vega-Lite updates, providing a stable and evolving tool for data visualization, primarily aimed at simplifying the creation of complex charts.
npm install vega-lite-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple bar chart using the Vega-Lite API. It includes the necessary imports and the critical `vl.register` step for browser or bundled environments, then builds a chart specification and outputs its JSON representation.
Migrate your project to use ES modules (`import`/`export`) or ensure your build tools/Node.js environment are configured to handle ESM. If running Node.js, ensure your package.json has `"type": "module"` or use the `.mjs` extension. For older Node.js, consider `--experimental-modules`.
Review existing uses of `selection.empty`. Replace string arguments with `true` or `false`, and ensure it's applied to the correct part of the selection definition. Consult the Vega-Lite v5 documentation for the updated parameters API.
Ensure `vega.js` and `vega-lite.js` scripts are loaded *before* `vega-lite-api.js`, and call `vl.register(vega, vegaLite, options)` at the beginning of your charting script.
Always check the `vega-lite-api` release notes for its compatible `vega-lite` version when performing a major version upgrade. Upgrade both packages concurrently to avoid compatibility issues.
Change your import statement to `import { vl } from 'vega-lite-api';`. Ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions for Node.js.In a browser, ensure `<script src="https://cdn.jsdelivr.net/npm/vega"></script>` and `<script src="https://cdn.jsdelivr.net/npm/vega-lite"></script>` are loaded before `<script src="https://cdn.jsdelivr.net/npm/vega-lite-api"></script>`, and `vl.register(vega, vegaLite, options)` is called. In a module environment, ensure `vega` and `vegaLite` are correctly imported and passed to `vl.register`.
Review your selection definitions. The `empty` method now takes a boolean (`true`/`false`) and should be applied to a predicate reference (e.g., `vl.selection().empty(false)`), not directly to the selection definition object. Refer to Vega-Lite v5+ documentation on parameters and selections.