Skip to content

Exporting

Type class

A plugin that exports the chart as an image, PDF or print, and its data as JSON, CSV, XLSX, HTML or a PDF table.

More info: Exporting

Sources

Exporting can be used (imported) via one of the following packages.

// Import Exporting
import * as am5plugins_exporting from "@amcharts/amcharts5/plugins/exporting";
// Create Exporting
am5plugins_exporting.Exporting.new(root, {
// ... config if applicable
});

Inheritance

Exporting extends Entity.

Exporting is not extended by any other symbol.

Settings

Set these settings on a Exporting object using its set() and setAll() methods. Read about settings concept.

backgroundColor

Type Color

Background color of exported images. If not set, it is taken from the CSS background of the chart's element, or the nearest parent that has one; white if none does.

backgroundOpacity

Type undefined | numberDefault 1Since 5.2.34

Opacity of the exported image's background: 0 (transparent) to 1 (opaque). JPEG has no transparency.

canvasOptions

Type IExportingImageOptions

Options for exportCanvas().

charset

Type undefined | stringDefault "utf-8"

Charset of exported files.

csvOptions

Type IExportingCSVOptions

CSV format options.

dataFields

Type undefined | object

Fields to include in data exports, and their column names: keys are fields in the data, values the column names.

dataFieldsOrder

Type string[]

Order of the fields in data exports.

dataSource

Type any

Data for data exports: an array of objects. Without it, the data formats are not offered.

More info: Exporting: exporting data

dateFields

Type string[]

Fields whose numbers are timestamps, exported as dates.

dateFormat

Type string | DateTimeFormatOptions

Date format for dates in data exports. If not set, the root's DateFormatter format is used.

durationFields

Type string[]Since 5.0.16

Fields whose numbers are durations, formatted with durationFormat.

durationFormat

Type undefined | stringSince 5.0.16

Format for the values in durationFields. If not set, the root's DurationFormatter format is used.

durationUnit

Type TimeUnitSince 5.0.16

Time unit the values in durationFields are in. If not set, the root's DurationFormatter baseUnit is used.

extraImages

Type Array

Other charts to add around the main chart in image exports.

filePrefix

Type undefined | stringDefault "chart"

Name of downloaded files, before the extension.

htmlOptions

Type IExportingHTMLOptions

HTML format options.

jpgOptions

Type IExportingImageOptions

JPEG format options.

jsonOptions

Type IExportingJSONOptions

JSON format options.

Type ExportingMenu

The ExportingMenu that offers the formats to the user.

numberFormat

Type string | NumberFormatOptions

Number format for the values in numericFields. If not set, they are exported as they are.

numericFields

Type string[]

Fields whose numbers are formatted with numberFormat.

pdfdataOptions

Type IExportingDataOptions

Options for the PDF with a data table.

pdfOptions

Type IExportingPDFOptions

PDF format options.

pngOptions

Type IExportingImageOptions

PNG format options.

printOptions

Type IExportingPrintOptions

Print options.

svgOptions

Type IExportingSVGOptionsSince 5.21.0

SVG format options.

title

Type undefined | string

Title of the export: the heading of a PDF, the page title when printing and the sheet name in XLSX.

xlsxOptions

Type IExportingXLSXOptions

XLSX format options.

9 inherited items
animations

Type ArrayInherited from IEntitySettingsSince 5.20.8

Animations the element plays on its own, described as data - so they can be set from a JSON config and saved with it.

Each one animates a setting of the element (or, with target: "dataItem", a value of its data item - a map point's positionOnLine, say). They start when the setting is applied, restart when it changes, and stop when the element is disposed. A saved config keeps what was configured, never a value caught half way through an animation.

sprite.set("animations", [
  { key: "rotation", to: 360, duration: 4000, loops: 0 },
  { key: "scale", from: 1, to: 1.3, duration: 800, loops: 0, yoyo: true, easing: "sine" }
]);
id

Type undefined | stringInherited from IEntitySettings

A unique ID for looking the element up in root.entitiesById. Setting an ID that another element already has throws an error.

ignoreThemes

Type undefined | false | trueDefault falseInherited from IEntitySettingsSince 5.15.6

Ignores themes: no theme rule applies to the element, not even one of the default theme.

stateAnimationDuration

Type undefined | numberDefault 0Inherited from IEntitySettings

How long, in milliseconds, a switch from one state to another animates.

0 switches at once.

stateAnimationEasing

Type $ease.EasingDefault out(cubic)Inherited from IEntitySettings

Easing of the animated switch from one state to another.

themes

Type ArrayInherited from IEntitySettings

Themes applied to the element and everything inside it.

themeTags

Type ArrayInherited from IEntitySettings

Tags that theme rules can target. They also count for the element's children, so a rule can match a child by a tag of its parent.

More info: Themes

themeTagsSelf

Type ArrayInherited from IEntitySettings

Tags that theme rules can target, like themeTags, but only for this element, not its children.

More info: Themes

userData

Type anyInherited from IEntitySettings

Any data of your own to keep with the element.

Private settings

These are read-only settings accessible from a Exporting object using its getPrivate() method. Read about private settings.

Exporting does not have any private settings.

Properties

className

StaticType stringDefault "Exporting"

classNames

StaticType ArrayDefault Entity.classNames.concat([Exporting.className])

7 inherited items
adapters

Type AdaptersDefault new Adapters(this)Inherited from Entity

enableDispose

Type booleanDefault trueInherited from Settings

Set to false to make dispose() do nothing.

events

Type EventDispatcherDefault this._createEvents()Inherited from Entity

root

Type RootInherited from EntitySince 5.0.6

The Root the object belongs to.

states

Type StatesDefault new States(this)Inherited from Entity

template

Type Template | undefinedInherited from Entity

A Template applied to the object. Its settings apply where the object has none set of its own.

uid

Type numberDefault ++counterInherited from Settings

A unique number, given to each object as it is created.

Methods

download(format: ExportingFormats,
customOptions?: IExportingFormatOptions
)

Returns Promise

Exports the chart or its data in a format and downloads the file, named filePrefix plus the format's extension.

export(format: ExportingFormats,
customOptions?: IExportingFormatOptions
)

Returns Promise

Exports the chart or its data in a format, as a data URI.

exportCanvas(customOptions?: IExportingImageOptions)

Returns Promise

Returns the chart image as a PNG data URI, using canvasOptions.

exportCSV(customOptions?: IExportingCSVOptions)

Returns Promise

Returns the data as a CSV file in a data URI.

exportHTML(customOptions?: IExportingHTMLOptions)

Returns Promise

Returns the data as an HTML table in a data URI.

exportImage(format: ExportingImageFormats,
customOptions?: IExportingImageOptions
)

Returns Promise

Returns the chart image as a data URI.

exportJSON(customOptions?: IExportingJSONOptions)

Returns Promise

Returns the data as a JSON file in a data URI.

exportPDF(customOptions?: IExportingPDFOptions)

Returns Promise

Returns a PDF of the chart image, with a data table if includeData is set, as a data URI.

exportPDFData(customOptions?: IExportingDataOptions)

Returns Promise

Returns a PDF of the data as a table, without the chart image, as a data URI.

exportSVG(customOptions?: IExportingSVGOptions)

Returns PromiseSince 5.21.0

Returns the chart image as an SVG data URI, whichever renderer the chart uses.

exportXLSX(customOptions?: IExportingXLSXOptions)

Returns Promise

Returns the data as an XLSX file in a data URI.

getCanvas(options: IExportingImageOptions)

Returns Promise

Returns a <canvas> element with an image of the chart and its extraImages.

getCSV(customOptions?: IExportingCSVOptions)

Returns Promise

Returns the data as CSV text.

getData(format: ExportingFormats,
customOptions?: IExportingDataOptions,
renameFields: boolean
)

Returns any

Returns the data prepared for export: only the dataFields, if set, with values formatted per the format's options.

getHTML(customOptions?: IExportingHTMLOptions)

Returns Promise

Returns the data as the markup of an HTML <table>.

getJSON(customOptions?: IExportingJSONOptions)

Returns Promise

Returns the data as a JSON string.

getPDF(customOptions?: IExportingPDFOptions,
includeImage: boolean,
includeData: boolean
)

Returns Promise

Returns a PDF file, Base64-encoded.

getSVG(customOptions?: IExportingSVGOptions)

Returns PromiseSince 5.21.0

Returns the chart image as SVG markup, with extraImages placed around it.

getXLSX(customOptions?: IExportingXLSXOptions)

Returns Promise

Returns the data as an XLSX file, Base64-encoded.

hasData()

Returns boolean

Checks whether dataSource is a non-empty array.

initiatePrint(data: string,
customOptions?: IExportingPrintOptions,
title?: undefined | string
)

Returns void

Prints an image, given as a data URI.

Returns Promise

Prints the chart.

streamFile(uri: string,
fileName: string,
addBOM: boolean
)

Returns boolean

Downloads a data URI as a file.

supportedExportTypes()

Returns ExportingTypes[]

Returns the export types available: "image" and "print", and "data" when there is data and the browser can download files.

supportedFormats()

Returns ExportingFormats[]

Returns the formats that can be exported: all that are not disabled, but the data formats only when there is data and the browser can download files.

22 inherited items
animate(options: AnimationOptions)

Returns AnimationInherited from Settings

Animates a setting from its current value (or from) to to. The setting jumps to from at once. With duration 0, or no value to start from, it is set to to at once and the returned animation is already stopped.

More info: Animations: animating settings

dispose()

Returns voidInherited from Settings

Disposes the object, freeing everything it holds. A disposed object can't be used again.

get(key: Key,
fallback: F
)

Returns NonNullable | FInherited from Entity

Returns the value of setting key, run through any adapters, or fallback if it is not set.

More info: Settings

has(key: Key)

Returns booleanInherited from Settings

Returns true if setting key is set.

More info: Settings

isDisposed()

Returns booleanInherited from Settings

Returns true if the object has been disposed.

isType(type: string)

Returns thisInherited from Entity

Returns true if the object is of class type or extends it.

new(root: Root,
settings: ITSettings,
template?: Template
)

StaticReturns TInherited from Entity

Creates an instance of the class. Use it instead of new Class().

More info: Getting started: new element syntax

off(key: Key,
callback?: undefined | (value: [""], target: this, key: Key) => void
)

Returns voidInherited from SettingsSince 5.9.2

Removes a callback added with on(). Without callback, removes all of them for key.

More info: Events: settings value change

offDebounced(key: Key,
callback?: undefined | (value: [""], target: this, key: Key) => void
)

Returns voidInherited from Settings

Removes a callback added with onDebounced(). Without callback, removes all of them for key.

More info: Events: settings value change

offDebouncedPrivate(key: Key,
callback?: undefined | (value: [""], target: this, key: Key) => void
)

Returns voidInherited from Settings

Removes a callback added with onPrivateDebounced(). Without callback, removes all of them for key.

More info: Events: settings value change

offPrivate(key: Key,
callback?: undefined | (value: [""], target: this, key: Key) => void
)

Returns voidInherited from SettingsSince 5.9.2

Removes a callback added with onPrivate(). Without callback, removes all of them for key.

More info: Events: settings value change

on(key: Key,
callback: (value: [""], target: this, key: Key) => void
)

Returns IDisposerInherited from Settings

Calls callback each time the value of setting key changes or is removed. Setting the same value again does not call it.

More info: Events: settings value change

once(key: Key,
callback: (value: [""], target: this, key: Key) => void
)

Returns IDisposerInherited from SettingsSince 5.20.4

Like on(), but the callback is removed after it is called once.

More info: Events: settings value change

onceDebounced(key: Key,
callback: (value: [""], target: this, key: Key) => void,
debounceDelay: number
)

Returns IDisposerInherited from SettingsSince 5.20.4

Like onDebounced(), but the callback is removed after it is called once.

More info: Events: settings value change

onDebounced(key: Key,
callback: (value: [""], target: this, key: Key) => void,
debounceDelay: number
)

Returns IDisposerInherited from Settings

Like on(), but waits until setting key has not changed for debounceDelay milliseconds, then calls callback once with the latest value.

More info: Events: settings value change

onPrivate(key: Key,
callback: (value: [""], target: this, key: Key) => void
)

Returns IDisposerInherited from Settings

Calls callback each time the value of private setting key changes.

More info: Events: settings value change

onPrivateDebounced(key: Key,
callback: (value: [""], target: this, key: Key) => void,
debounceDelay: number
)

Returns IDisposerInherited from Settings

Like onPrivate(), but waits until private setting key has not changed for debounceDelay milliseconds, then calls callback once with the latest value.

More info: Events: settings value change

remove(key: Key)

Returns voidInherited from Entity

Removes the value set for setting key. The setting goes back to the value from a theme or template, if one has it.

More info: Settings

removeAll()

Returns voidInherited from Settings

Removes all settings, as remove() does for each one.

More info: Settings

set(key: Key,
value: Value
)

Returns ValueInherited from Entity

Sets setting key to value and returns value. A value set this way overrides themes and templates, and stops any animation of the setting.

More info: Settings

setAll(settings: Partial)

Returns voidInherited from Settings

Sets several settings at once, from an object of key-value pairs.

More info: Settings

setTimeout(fn: () => void,
delay: number
)

Returns IDisposerInherited from Entity

Calls fn after delay milliseconds, unless the object is disposed first. Disposing the returned disposer cancels it.

Events

Add event handlers to Exporting object using its events.on() method. Read about adding event handlers.

dataprocessed

Param { type: "dataprocessed", target: Exporting, data: any } & IExportEvent

The data for a data export is prepared. A listener can still change data.

downloadstarted

Param { type: "downloadstarted", target: Exporting, fileName: string } & IExportEvent

A download was requested, before its file is generated.

exportfinished

Param { type: "exportfinished", target: Exporting } & IExportEvent

An export was set off. It is dispatched before the result is ready, so to use the result, wait for the promise export() returns.

exportstarted

Param { type: "exportstarted", target: Exporting } & IExportEvent

An export started.

pdfdocready

Param { type: "pdfdocready", target: Exporting, doc: any } & IExportEvent

The PDF document definition is prepared. A listener can still change it before the PDF is made.

printstarted

Param { type: "printstarted", target: Exporting } & IExportEvent

Printing was requested, before the image to print is generated.

workbookready

Param { type: "workbookready", target: Exporting, workbook: any, workbookOptions: any, xlsx: any } & IExportEvent

The XLSX workbook is prepared. A listener can still change it before it is written.