---
id: "packages/active-charts/all-exports/export"
title: "Export"
description: "exportChartAsPng, PngExportOptions, exportChartAsSvg, SvgExportOptions and 10 more: generated from the source of active-charts."
url: "/packages/active-charts/all-exports/export"
locale: "en"
revision: "g0mvjxwj5c-88bdbe1c:export"
---

# Export

Exported by `@workspace/active-charts`. Generated from the package source; part of [the index of every export](/packages/active-charts/all-exports).

## Functions, hooks and constants

**exportChartAsPng**: `(svgElement: SVGSVGElement, filename: string, scale?: number, options?: PngExportOptions) => Promise<ChartExportResult>`

Exports a chart SVG element as a PNG image.
The chart is captured as the live chart shows it, then the SVG
is rendered on an offscreen Canvas at the specified scale (default 2x for
high-DPI).

With `options.fonts` the faces are loaded before the capture moment and
embedded as data URLs, so the image carries no network dependency and the
page's own fonts are not read.

Pass `options.legendItems` to inline the chart legend into the PNG.

Resolves with the one PNG it produced, handed to the browser
unless `options.download` is `false`; an inherit-mode PNG whose live web
font could not be embedded carries a `font-fallback` warning. Rejects
with a `ChartExportError` when no file could be produced.

**exportChartAsSvg**: `(svgElement: SVGSVGElement, filename: string, options?: SvgExportOptions) => Promise<ChartExportResult>`

Exports a chart SVG element as a standalone .svg file, once the chart is
still (no animation half-way, W11). Every colour the chart declares is
materialised as the live chart shows it; the host font stays
named, so the file shows it wherever that font is installed.

With `options.fonts` the file names the host's export families first, and embeds their faces when the set asks for it. The faces are
loaded before the capture moment. Whether a viewer honours embedded faces
is the viewer's: browsers do, other tools may not.

Resolves with the one SVG file it produced, handed to the
browser unless `options.download` is `false`; rejects with a
`ChartExportError` when it could not be produced.

**exportChartAsPdf**: `(svgElement: SVGSVGElement, filename: string, options?: ExportPdfOptions) => Promise<ChartExportResult>`

Exports a chart SVG element as a standalone `.pdf` file using
jsPDF + svg2pdf.js. Both libraries are loaded via dynamic `import()` so
they stay out of the main bundle for consumers that never call this.

The chart is captured once it is still (W11), in the capture every image
export shares: its colours are materialised as the live chart
shows them, and the page takes the chart's background unless the host names
another.

Text (ADR-058, the L3a tier of ADR-054): every text element passes a
refusal guard (complex scripts, combining marks, joiners and selectors,
emoji, the supplementary planes), then draws in the first family of
`options.fonts` that covers all of it, or, without fonts, in Helvetica if
it is WinAnsi. Anything else rejects with a coded `ChartExportError`; the
PDF never draws a glyph it cannot vouch for. The fonts are loaded and read
before the capture moment.

Pass `options.legendItems` to inline the chart legend and `options.report`
for the host's title, subtitle and caption. Resolves with the one PDF it
produced, handed to the browser unless `options.download` is
`false`; rejects with an error when it could not be produced.

**ChartExportError**

```ts
class ChartExportError extends Error {
  readonly code: ChartExportErrorCode;
  readonly format?: ChartExportFormat;
  readonly missingModule?: string;
  readonly family?: string;
  readonly detected?: FontByteFormat;
  readonly codePoint?: number;
  readonly reason?: PdfTextRefusalReason;
  readonly script?: string;
  readonly normalizable?: boolean;
  readonly families?: readonly string[];
  constructor(message: string, options: ChartExportErrorOptions);
}
```

Why an export did not produce a file.

**exportChartAsCsv**: `(data: ChartDatum[], columns: string[], filename: string, options?: CsvExportOptions) => Promise<ChartExportResult>`

Exports chart data as a CSV file. Resolves with the one file it produced, handed to the browser unless `options.download` is `false`;
asynchronous like every export, so a host has one rule.

## Types

**PngExportOptions**

```ts
interface PngExportOptions {
  backgroundColor?: string;
  legendItems?:
    | readonly ChartExportLegendItem[]
    | (() => readonly ChartExportLegendItem[] | undefined);
  legendOptions?: ChartExportLegendOptions;
  report?: ExportReportText;
  fonts?: ChartExportFonts;
  download?: boolean;
}
```

**SvgExportOptions**

```ts
interface SvgExportOptions {
  legendItems?:
    | readonly ChartExportLegendItem[]
    | (() => readonly ChartExportLegendItem[] | undefined);
  legendOptions?: ChartExportLegendOptions;
  report?: ExportReportText;
  fonts?: ChartExportFonts;
  download?: boolean;
}
```

**ChartExportErrorCode**

```ts
type ChartExportErrorCode =
  | 'EXPORT_DEPENDENCY_MISSING'
  | 'EXPORT_CAPTURE_FAILED'
  | 'EXPORT_NO_DATA'
  | 'EXPORT_FONT_REQUIRED'
  | 'EXPORT_FONT_FORMAT_UNSUPPORTED'
  | 'EXPORT_FONT_FACE_MISSING'
  | 'EXPORT_FONT_SOURCE_INVALID'
  | 'EXPORT_FONT_LOAD_FAILED'
  | 'EXPORT_TEXT_UNSUPPORTED'
  | 'EXPORT_GLYPH_COVERAGE';
```

Why an export did not produce a file, stable across message wording. The font codes belong to every format that consumes an export
font set (PDF, and SVG and PNG since ADR-059); the text codes to PDF.

**ChartExportErrorOptions**

```ts
interface ChartExportErrorOptions {
  code: ChartExportErrorCode;
  cause?: unknown;
  format?: ChartExportFormat;
  missingModule?: string;
  family?: string;
  detected?: FontByteFormat;
  codePoint?: number;
  reason?: PdfTextRefusalReason;
  script?: string;
  normalizable?: boolean;
  families?: readonly string[];
}
```

What a {@link ChartExportError} carries besides its code. Never the
exported text: at most one code point and a script name.

**ExportPdfOptions**

```ts
interface ExportPdfOptions {
  pageSize?: PdfPageSize;
  orientation?: 'portrait' | 'landscape';
  scale?: number;
  backgroundColor?: string;
  legendItems?:
    | readonly ChartExportLegendItem[]
    | (() => readonly ChartExportLegendItem[] | undefined);
  legendOptions?: ChartExportLegendOptions;
  margin?: number;
  report?: ExportReportText;
  fonts?: ChartExportFonts;
  download?: boolean;
}
```

**PdfPageSize**

```ts
type PdfPageSize = 'a4' | 'letter' | [number, number];
```

Page size accepted by jsPDF. Besides the named presets we allow an
explicit `[width, height]` tuple in the unit matching jsPDF's default
(points, 1pt = 1/72 in).

**CsvColumnSemantics**

```ts
type CsvColumnSemantics = Readonly<Record<string, CsvValueSemantic>>;
```

Explicit semantics per column key; a column not listed is left as it is.

**CsvExportOptions**

```ts
interface CsvExportOptions {
  columnSemantics?: CsvColumnSemantics;
  download?: boolean;
}
```

Options for the machine CSV.

**CsvValueSemantic**

```ts
type CsvValueSemantic = 'date' | 'dateTime';
```

The temporal meaning of a column in the machine CSV.

- `'date'` — a **calendar day**: the same day in every time zone, written
without a time part (`2026-01-19`);
- `'dateTime'` — an **instant** on the timeline, written with its time and
zone (`2026-01-19T00:00:00.000Z`).

This says what the value IS, not how it should look: the machine CSV knows
no language, locale or presentation profile.
