# svelte-vega

> Render Vega or Vega-Lite charts using a Svelte component.

Latest version **4.1.0** (published 2026-01-06) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install svelte-vega
pnpm add svelte-vega
yarn add svelte-vega
bun add svelte-vega
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities; has provenance.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-01-06 |
| First published | 2021-04-21 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 25.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 79 |
| Author | Alex Bäuerle |
| Maintainers | domoritz, cabreraalex |
| Keywords | Vega-Lite, Vega, Visualization, Svelte |

## Links

- npm: https://www.npmjs.com/package/svelte-vega
- Repository: https://github.com/vega/svelte-vega
- Homepage: https://github.com/vega/svelte-vega#readme
- Issues: https://github.com/vega/svelte-vega/issues
- npm.io page: https://npm.io/package/svelte-vega

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-01-06
- 4.0.1 — 2025-04-30
- 4.0.0 — 2025-03-29
- 3.0.2 — 2024-11-18
- 3.0.1 — 2024-11-18
- 3.0.0 — 2024-11-11
- 2.3.0 — 2024-11-11
- 2.2.1 — 2024-05-10
- 2.2.0 — 2024-03-20
- 2.1.0 — 2023-07-24
- 2.0.0 — 2023-04-13
- 1.2.0 — 2022-11-01
- 1.1.1 — 2022-06-09
- 1.1.0 — 2021-05-20
- 1.0.0 — 2021-05-03
- … 6 more at https://npm.io/package/svelte-vega/versions

## README

# svelte-vega [![NPM version][npm-image]][npm-url]

> Use `vega` or `vega-lite` in `svelte` applications!

## Install

In your Svelte project, install `svelte-vega` with the following:

```bash
yarn add svelte-vega
```

or

```bash
npm install svelte-vega --save
```

[npm-image]: https://img.shields.io/npm/v/svelte-vega.svg
[npm-url]: https://npmjs.org/package/svelte-vega

## Example Code

The following contains code samples for Svelte Vega and Vega-Lite components using TypeScript.
For an example Svelte project using `svelte-vega`, see the [example application](https://github.com/vega/svelte-vega/tree/main/packages/sample-project).

### Svelte `<Vega>` Component

```typescript
<script lang="ts">
  import type { VisualizationSpec } from "svelte-vega";
  import { Vega } from "svelte-vega";

  const data = {
    table: [
      { category: "A", amount: 28 },
      { category: "B", amount: 55 },
      { category: "C", amount: 43 },
      { category: "D", amount: 91 },
      { category: "E", amount: 81 },
      { category: "F", amount: 53 },
      { category: "G", amount: 19 },
      { category: "H", amount: 87 },
    ],
  };

  // For an example, see https://github.com/vega/svelte-vega/blob/main/packages/storybook/stories/spec1.ts
  const spec: VisualizationSpec = // any vega spec.
</script>

<Vega {data} {spec} />
```

### Svelte `<VegaLite>` Component

```typescript
<script lang="ts">
  import type { VisualizationSpec } from "svelte-vega";
  import { VegaLite } from "svelte-vega";

  const data = {
    table: [
      { category: "A", amount: 28 },
      { category: "B", amount: 55 },
      { category: "C", amount: 43 },
      { category: "D", amount: 91 },
      { category: "E", amount: 81 },
      { category: "F", amount: 53 },
      { category: "G", amount: 19 },
      { category: "H", amount: 87 },
    ],
  };

  const spec: VisualizationSpec = {
    $schema: "https://vega.github.io/schema/vega-lite/v5.json",
    description: "A simple bar chart with embedded data.",
    data: {
      name: "table",
    },
    mark: "bar",
    encoding: {
      x: { field: "category", type: "nominal" },
      y: { field: "amount", type: "quantitative" },
    },
  }
</script>

<VegaLite {data} {spec} />
```

---
_Source: https://npm.io/package/svelte-vega · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
