SVG, PNG and CSV export

Vector images, raster images and original observations.

Get the SVG

exportSvg returns the full chart with visible title, description and legend, plot and axes. composition:plot retains a compact plot-only export. On the server, renderChartSvg keeps its default plot output for SSR; request composition:chart for a complete image.

chart-svg.ts
import type { ChartController } from '@neural-charts/web';

export function getSvg(chart: ChartController): string {
  return chart.exportSvg({ composition: 'chart' });
}

Scope

exportPng returns a Blob and accepts composition, legend, description, pixelRatio, width, height, background and signal. SVG/PNG preserve theme, patterns, title and legend. legend:false or description:false omit those parts. Canvas only rasterizes exports. exportCsv retains original data and formula-injection protection. Destroy cancels pending exports and releases temporary URLs. Fonts use the local system stack without required external resources.

Choose the output
MethodResultUse
exportSvg()stringVector image with visible title and legend.
exportPng(options)Promise<Blob>Rasterized image in the browser.
exportCsv(options)Validated resultOriginal data, not rounded label values.

Chart toolbar

Combine ChartToolbarAction.Csv, Png, Svg and Zoom in toolbar.actions. The list order places each download and the group of three zoom icons. Use ChartToolbarPosition.Top to place the toolbar above the plot or Bottom for below, the default. Zoom requires viewport on a supported chart. The group is added by default when a viewport is active. Set viewport.controls: false to control its presence through toolbar.actions alone. When toolbar is set, its downloads replace downloadMenu. CSV, PNG and SVG download directly using instanceId as the filename. PNG downloads at 2×. For a download-only toolbar you can also use downloadMenu with ChartDownloadFormat and downloadMenuPosition.

download-menu.ts
import {
  ChartToolbarAction, ChartToolbarPosition, createChart,
  type ChartData, type ChartOptions, type ChartZoomOptions,
} from '@neural-charts/web';

const zoom: ChartZoomOptions = {
  min: 0.1,
  max: 50,
  step: 0.1,
  increment: 1,
  label: 'Magnification',
};

const options: ChartOptions = {
  viewport: { axes: 'x', controls: false, zoom },
  toolbar: {
    position: ChartToolbarPosition.Top,
    actions: [
      ChartToolbarAction.Zoom, ChartToolbarAction.Csv,
      ChartToolbarAction.Png, ChartToolbarAction.Svg,
    ],
  },
};

export function mountChart(host: HTMLElement, data: ChartData) {
  return createChart(host, data, options, { instanceId: 'weekly-visits' });
}