Export
Type class
Export allows downloading of current snapshot of the chart as an image, PDF, or its data in various formats.
The export functionality is enabled by default in charts and is accessible via API or optional export menu.
To enable menu, simply access export's menu property. E.g.:
chart.exporting.menu = new am4core.ExportMenu();
chart.exporting.menu = new am4core.ExportMenu();
{
// ...
"exporting": {
"menu": {}
}
}
To export via API, use export() method:
chart.exporting.export(type, [options]);
chart.exporting.export(type, [options]);
E.g.:
chart.exporting.export("png");
chart.exporting.export("png");
Sources
Export can be used (imported) via one of the following packages.
/** * Import from: "core.ts" * Use like: am4core.Export */import * as am4core from "@amcharts/amcharts4/core";/** * Include via: <script src="core.js"></script> * Access items like: am4core.Export */Inheritance
Export extends Validatable.
Export is not extended by any other symbol.
Properties
adapterType
Adapter<Export,IExportAdapters>Defaultnew Adapter<Export, IExportAdapters>(this)Adapter.
backgroundColorType
$type.Optional<Color>A background color to be used for exported images. If set, this will override the automatically acquired background color.
containerType
HTMLElementA reference to a container to be used to place
ExportMenuin.dataType
anyData to export.
dataFieldsType
anyData fields in
{ field: fieldName }format. Those are used for exporting in data formats to name the columns.More info: Exporting Charts: changing order and names of columns for examples and details
dataFieldsOrderType
string[]Default[]Since 4.9.7Holds an array of data field names. If set, exported data fields will try to maintain this order.
If not set (default), the export will try to maintain the same order as in source data, or as in
dataFields(if set).dateFieldsType
List<string>A list of fields that hold date values.
dateFormatType
$type.Optional<string|DateTimeFormatOptions>A date format to use for exporting dates. Will use
DateFormatterformat if not set.dateFormatterType
DateFormatterA
DateFormatterto use when formatting dates when exporting data.durationFieldsType
List<string>A list of fields that hold duration values.
durationFormatType
$type.Optional<string>A format to use when formatting values from
durationFields.Will use
DurationFormatterformat if not set.durationFormatterType
DurationFormatterA
DurationFormatterto use when formatting duration values when exporting data.extraSpritesType
Array<Sprite|IExportCanvas>Since 4.2.0An array of extra
Spriteelements to include in export.It can be used to export any external elements, or even other charts.
E.g.:
chart.exporting.extraSprites.push(chart2);chart.exporting.extraSprites.push(chart2);IMPORTANT: This setting is ignored when exporting to SVG format.
filePrefixType
stringA file prefix to be used for all exported formats.
Export will apply format-related extension to it. E.g. if this is set to "myExport", the file name of the PNG exported image will be "myExport.png".
formatOptionsType
Dictionary<string,ExportOptions>Since 4.9.12A
Dictionaryobject containing format-specific options.May be used to change specific option for the format:
chart.exporting.formatOptions.getKey("csv").disabled = true;chart.exporting.formatOptions.getKey("csv").disabled = true;{ // ... "exporting": { // ... "formatOptions": { "csv": { "disabled": true } } } }languageType
LanguageA
Languageinstance to be used for translations.Type
$type.Optional<ExportMenu>An instance of
ExportMenu.To add an export menu to a chart, set this to a new instance of
ExportMenu.chart.exporting.menu = new am4core.ExportMenu();chart.exporting.menu = new am4core.ExportMenu();{ // ... "exporting": { "menu": {} } }numberFieldsType
List<string>Since 4.5.15A list of fields that hold number values.
numberFormatType
$type.Optional<string>Since 4.5.15A number format to use for exporting dates. Will use
NumberFormatterformat if not set.numberFormatterType
NumberFormatterSince 4.5.15A
NumberFormatterto use when formatting dates when exporting data.preloaderType
PreloaderReturns a an instance of
Preloaderassociated with the Sprite being exported.spriteType
SpriteA reference to
Spriteto export. Can be any Sprite, including some internal elements.timeoutDelayType
numberDefault2000If export operation takes longer than milliseconds in this second, we will show a modal saying export operation took longer than expected.
titleType
$type.Optional<string>A title to be used when printing.
useRetinaType
booleanDefaulttrueMany modern displays have use more actual pixels per displayed pixel. This results in sharper images on screen. Unfortunately, when exported to a bitmap image of the sam width/height size it will lose those extra pixels, resulting in somewhat blurry image.
This is why we are going to export images larger than they are, so that we don't lose any details.
If you'd rather export images without change in size, set this to
false.useSimplifiedExportType
booleanDefaulttrueSince 4.2.5By default Export will try to use built-in method for transforming chart into an image for download, then fallback to external library (canvg) for conversion if failed.
Setting this to
falsewill force use of external library for all export operations.It might be useful to turn off simplified export if you are using strict content security policies, that disallow images with blobs as their source.
useWebFontsType
booleanDefaulttrueIf you are using web fonts (such as Google Fonts), your chart might be using them as well.
Normally, exporting to image will require to download these fonts so the are carried over to exported image.
This setting can be used to disable or enable this functionality.
validateSpritesType
Array<Sprite>Since 4.6.8An array of
Spriteelements that need to be valid before export commences.If any of those elements is not completely ready when export is triggered, the export will wait until they are (their
validatedevent triggers) before going through with the export opertaion.This is useful if you need to modify chart appearance for the export.
E.g.:
// Add watermark let watermark = chart.createChild(am4core.Label); watermark.text = "Copyright (C) 2019"; watermark.disabled = true; // Add watermark to validated sprites chart.exporting.validateSprites.push(watermark); // Enable watermark on export chart.exporting.events.on("exportstarted", function(ev) { watermark.disabled = false; }); // Disable watermark when export finishes chart.exporting.events.on("exportfinished", function(ev) { watermark.disabled = true; });// Add watermark var watermark = chart.createChild(am4core.Label); watermark.text = "Copyright (C) 2019"; watermark.disabled = true; // Add watermark to validated sprites chart.exporting.validateSprites.push(watermark); // Enable watermark on export chart.exporting.events.on("exportstarted", function(ev) { watermark.disabled = false; }); // Disable watermark when export finishes chart.exporting.events.on("exportfinished", function(ev) { watermark.disabled = true; });webFontFilterType
RegExpSince 4.10.17A regular expression that will be matched against each URL of an external font being loaded. Font will only be loaded of regular expression matches.
Has no effect of
useWebFontsis set tofalse.chart.exporting.webFontFilter = /pacifico|roboto/;chart.exporting.webFontFilter = /pacifico|roboto/;{ // ... "exporting": { // ... "webFontFilter": /pacifico|roboto/ } }
5 inherited items
clonedFromType
$type.Optional<this>Inherited fromBaseObjectReference to the original object this object was cloned from. We need to keep this so we can disassociate it from source object when this object is disposed.
configType
objectInherited fromBaseObjectUse this property to set JSON-based config. When set, triggers processing routine, which will go through all properties, and try to apply values, create instances, etc.
Use this with caution, as it is a time-consuming process. It's used for initialchart setup only, not routine operations.
eventsType
EventDispatcher<AMEvent<this,IBaseObjectEvents>>Inherited fromBaseObjectEventsAn
EventDispatcherinstanceidType
$type.Optional<string>Inherited fromBaseObjectSets the user-defined id of the element.
uidType
stringInherited fromBaseObjectReturns object's internal unique ID.
Methods
constructor(container:HTMLElement)Returns
ExportConstructor
download(uri:string,
fileName:string,
addBOM:boolean)Returns
Promise<boolean>Triggers download of the file.
This is an asynchronous function. Check the description of
getImage()for description and example usage.downloadSupport()Returns
booleanReturns
trueif browser has any supported methods to trigger download of a binary file.export(type:Key,
options?:IExportOptions[""])Returns
Promise<boolean>Initiates export procedure.
getCanvas(options?:IExportImageOptions)Returns
Promise<HTMLCanvasElement>Returns canvas representation of the
Sprite.getCanvasAdvanced(options?:IExportImageOptions)Returns
Promise<HTMLCanvasElement>Returns canvas representation of the
Spriteusing canvg.getContentType(type:Key)Returns
stringReturns proper content type for the export type.
getCSV(type:"csv",
options?:IExportCSVOptions,
encodeURI:boolean)Returns
Promise<string>Returns chart's data formatted as CSV.
This is an asynchronous function. Check the description of
getImage()for description and example usage.getExcel(type:"xlsx",
options?:IExportExcelOptions)Returns
Promise<string>Returns an Excel file of chart's data.
This is an asynchronous function. Check the description of
getImage()for description and example usage.getFormatOptions(type:Key)Returns
IExportOptions[""]Returns current options for a format.
getHTML(type:"html",
options?:IExportHTMLOptions,
encodeURI:boolean)Returns
Promise<string>Since 4.7.0Returns chart's data formatted as HTML table.
This is an asynchronous function. Check the description of
getImage()for description and example usage.getImage(type:Key,
options?:IExportImageOptions,
includeExtras?:boolean)Returns
Promise<string>Produces image output from the element.
Converts to a
Canvasfirst, then produces an image to download.This is an asynchronous function. Rather than returning a result, it returns a Promise.
You can use
awaitnotion from other async functions, orthen()anywhere else.let img; // Async img = await chart.exporting.getImage( "png" ); // Sync chart.exporting.getImage( "png" ).then( ( data ) => { img = data; } );var img; chart.exporting.getImage( "png" ).then( ( data ) => { img = data; } );getImageAdvanced(type:imageFormats,
options?:IExportImageOptions,
includeExtras?:boolean)Returns
Promise<string>Tries to dynamically load canvg.js and export an image using its functions.
This is an asynchronous function. Check the description of
getImage()for description and example usage.getJSON(type:"json",
options?:IExportJSONOptions,
encodeURI:boolean)Returns
Promise<string>Returns chart's data in JSON format.
This is an asynchronous function. Check the description of
getImage()for description and example usage.getPDF(type:"pdf"|"pdfdata",
options?:IExportPDFOptions)Returns
Promise<string>Returns a PDF containing chart image.
This is an asynchronous function. Check the description of
getImage()for description and example usage.getPDFData(type:"pdf",
options?:IExportPDFOptions)Returns
Promise<any>Since 4.7.0Returns chart's data formatted suitable for PDF export (pdfmake).
This is an asynchronous function. Check the description of
getImage()for description and example usage.getPrint(type:string,
options?:IExportPrintOptions)Returns
Promise<string>Requests a Print of the chart.
getSVG(type:"svg",
options?:IExportSVGOptions,
encodeURI:boolean)Returns
Promise<string>Returns an SVG representation of the chart.
This is an asynchronous function. Check the description of
getImage()for description and example usage.print(data:string,
options?:IExportPrintOptions,
title?:string)Returns
Promise<boolean>Initiates print of the chart.
This is an asynchronous function. Check the description of
getImage()for description and example usage.setFormatOptions(type:Key,
options:IExportOptions[""])Returns
voidSets options for a format.
typeSupported(type:Key)Returns
booleanChecks if this specific menu item type is supported by current system.
7 inherited items
clone(cloneId?:string)Returns
thisInherited fromBaseObjectMakes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them.
copyFrom(source:this)Returns
voidInherited fromBaseObjectEventsCopies all parameters from another
Sprite.dispatch(eventType:Key,
data?:any)Returns
voidInherited fromBaseObjectEventsDispatches an event using own event dispatcher. Will automatically populate event data object with event type and target (this element).
It also checks if there are any handlers registered for this sepecific event.
dispatchImmediately(eventType:Key,
data?:any)Returns
voidInherited fromBaseObjectEventsWorks like
dispatch, except event is triggered immediately, without waiting for the next frame cycle.dispose()Returns
voidInherited fromValidatablegetCurrentThemes()Returns
ITheme[]Inherited fromBaseObjectReturns a list of themes that should be applied to this element. It could either be a list of themes set explicitly on this element, or system-wide.
isDisposed()Returns
booleanInherited fromBaseObjectReturns if this object has been already been disposed.
Events
errorParam { type:
"error", target:Export} &ExportOperationInvoked when export operation encounters error.
exportfinishedParam { type:
"exportfinished", target:Export} &ExportOperationInvoked when export operation finishes.
exportstartedParam { type:
"exportstarted", target:Export} &ExportOperationInvoked when the Export starts export procedure.
You can use event handlers here to modify config before actual export starts.
exporttimedoutParam { type:
"exporttimedout", target:Export} &ExportOperationInvoked when export operation times out.
Use Export's
timeoutDelaysetting to set timeout. (default: 2000ms)initedParam { type:
"inited", target:Export}Invoked when Export initializes.
Param { type:
"menucreated", target:Export}Invoked when Export menu is created.
Adapters
backgroundColorParam { backgroundColor:
$type.Optional<Color> }charsetParam { charset:
string, options:IExportOptions[""], type:Keys}containerParam { container:
HTMLElement}contentTypeParam { contentType:
string, type:Keys}dataParam { data:
Array<any> }dataFieldNameParam { field:
string, name:string}dataFieldsParam { dataFields:
any}dataFieldsOrderParam { dataFieldsOrder:
string[], format:string}dateFieldsParam { dateFields:
any}dateFormatParam { dateFormat:
$type.Optional<string|DateTimeFormatOptions> }dateFormatterParam { dateFormatter:
DateFormatter}durationFieldsParam { durationFields:
any}durationFormatParam { durationFormat:
$type.Optional<string> }durationFormatterParam { durationFormatter:
DurationFormatter}exportFunctionParam { func: (type:
Key, options:IExportOptions[""]) =>Promise<any>, options:IExportOptions[""], type:Keys}extraSpritesParam { extraSprites:
Array<Sprite|IExportCanvas> }filePrefixParam { filePrefix:
string}formatDataFieldsParam { dataFields:
any, format:string}getCSVParam { data:
string, options:IExportOptions[""]}getExcelParam { data:
string, options:IExportOptions[""]}getHTMLParam { data:
string, options:IExportOptions[""]}getJSONParam { data:
string, options:IExportOptions[""]}getSVGParam { data:
string, options:IExportOptions[""]}isDateFieldParam { field:
string, isDateField:boolean}isDurationFieldParam { field:
string, isDurationField:boolean}isNumberFieldParam { field:
string, isNumberField:boolean}normalizeSVGParam { data:
string, options:IExportOptions[""]}numberFieldsParam { numberFields:
any}numberFormatParam { numberFormat:
$type.Optional<string> }numberFormatterParam { numberFormatter:
NumberFormatter}optionsParam { options:
IExportOptions[""], type:Keys}pdfmakeDocumentParam { doc:
any, options:IExportOptions[""]}pdfmakeTableParam { options:
IExportOptions[""], table:any}spriteParam { sprite:
Sprite}supportedParam { options:
IExportOptions[""], supported:boolean, type:Keys}svgToDataURIParam { data:
string, options:IExportOptions[""]}timeoutMessageParam { message:
string}titleParam { options:
IExportOptions[""], title:$type.Optional<string> }validateSpritesxlsxSheetNameParam { name:
string, xlsx:any}xlsxWorkbookParam { options:
IExportOptions[""], workbook:any, xlsx:any}Since 4.9.28xlsxWorkbookOptionsParam { options:
any, xlsx:any}