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");
@todo Better loading indicator?
@todo Implement multiplier option
@todo Handling of hanged exports
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: am4.Export * -------------------------------------------------------- */
Inheritance
Export extends Validatable
.
Export is not extended by any other symbol.
Properties
adapter # |
Type Default Adapter. |
---|---|
backgroundColor # |
Type A background color to be used for exported images. If set, this will override the automatically acquired background color. |
clonedFrom # |
Type Inherited from Reference 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. |
config # |
Type Inherited from Use 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. |
container # |
Type A reference to a container to be used to place |
data # |
Type Data to export. |
dataFields # |
Type Data fields in Click here for examples and details |
dataFieldsOrder # |
Type Default Holds 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 @since 4.9.7 |
dateFields # |
Type A list of fields that hold date values. |
dateFormat # |
Type A date format to use for exporting dates. Will use |
dateFormatter # |
Type A |
durationFields # |
Type A list of fields that hold duration values. |
durationFormat # |
Type A format to use when formatting values from Will use |
durationFormatter # |
Type A |
events # |
Type Inherited from An |
extraSprites # |
Type An array of extra 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. @since 4.2.0 |
filePrefix # |
Type A 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". |
formatOptions # |
Type A 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 } } } } @since 4.9.12 |
id # |
Type Inherited from Sets the user-defined id of the element. |
language # |
Type A |
menu # |
Type An instance of To add an export menu to a chart, set this to a new instance of chart.exporting.menu = new am4core.ExportMenu(); chart.exporting.menu = new am4core.ExportMenu(); { // ... "exporting": { "menu": {} } } |
numberFields # |
Type A list of fields that hold number values. @since 4.5.15 |
numberFormat # |
Type A number format to use for exporting dates. Will use @since 4.5.15 |
numberFormatter # |
Type A @since 4.5.15 |
preloader # |
Type Returns a an instance of |
sprite # |
Type A reference to |
timeoutDelay # |
Type Default If export operation takes longer than milliseconds in this second, we will show a modal saying export operation took longer than expected. |
title # |
Type A title to be used when printing. |
uid # |
Type Inherited from Returns object's internal unique ID. |
useRetina # |
Type Default Many 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 |
useSimplifiedExport # |
Type Default By 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 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. @since 4.2.5 |
useWebFonts # |
Type Default If 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. |
validateSprites # |
Type An array of If any of those elements is not completely ready when export is triggered, the export will wait until they are (their 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; }); @since 4.6.8 |
webFontFilter # |
Type A 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 chart.exporting.webFontFilter = /pacifico|roboto/; chart.exporting.webFontFilter = /pacifico|roboto/; { // ... "exporting": { // ... "webFontFilter": /pacifico|roboto/ } } @since 4.10.17 |
There are 5 inherited items currently hidden from this list. |
Methods
clone( cloneId?: ) |
Returns Inherited from Makes a copy of this object and returns the clone. Try to avoid cloning complex objects like chart, create new instances if you need them. |
---|---|
constructor( container: ) |
Returns Constructor |
copyFrom( source: ) |
Returns Inherited from Copies all parameters from another |
dispatch( eventType: ) |
Returns Inherited from Dispatches 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: ) |
Returns Inherited from Works like |
dispose() |
Returns Inherited from |
download( uri: ) |
Returns Triggers download of the file. This is an asynchronous function. Check the description of @async |
downloadSupport() |
Returns Returns |
export( type: ) |
Returns Initiates export procedure. @async |
getCSV( type: ) |
Returns Returns chart's data formatted as CSV. This is an asynchronous function. Check the description of @async |
getCanvas( options?: ) |
Returns Returns canvas representation of the |
getCanvasAdvanced( options?: ) |
Returns Returns canvas representation of the |
getContentType( type: ) |
Returns Returns proper content type for the export type. |
getCurrentThemes() |
Returns Inherited from Returns 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. |
getExcel( type: ) |
Returns Returns an Excel file of chart's data. This is an asynchronous function. Check the description of @async |
getFormatOptions( type: ) |
Returns Returns current options for a format. |
getHTML( type: ) |
Returns Returns chart's data formatted as HTML table. This is an asynchronous function. Check the description of @since 4.7.0 |
getImage( type: ) |
Returns Produces image output from the element. Converts to a This is an asynchronous function. Rather than returning a result, it returns a Promise. You can use 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: ) |
Returns Tries to dynamically load canvg.js and export an image using its functions. This is an asynchronous function. Check the description of |
getJSON( type: ) |
Returns Returns chart's data in JSON format. This is an asynchronous function. Check the description of @async |
getPDF( type: ) |
Returns Returns a PDF containing chart image. This is an asynchronous function. Check the description of @async |
getPDFData( type: ) |
Returns Returns chart's data formatted suitable for PDF export (pdfmake). This is an asynchronous function. Check the description of @since 4.7.0 |
getPrint( type: ) |
Returns Requests a Print of the chart. @async |
getSVG( type: ) |
Returns Returns an SVG representation of the chart. This is an asynchronous function. Check the description of |
isDisposed() |
Returns Inherited from Returns if this object has been already been disposed. |
print( data: ) |
Returns Initiates print of the chart. This is an asynchronous function. Check the description of @async |
setFormatOptions( type: ) |
Returns Sets options for a format. |
typeSupported( type: ) |
Returns Checks if this specific menu item type is supported by current system. |
There are 7 inherited items currently hidden from this list. |
Events
#error |
Param { type: Invoked when export operation encounters error. |
---|---|
#exportfinished |
Param { type: Invoked when export operation finishes. |
#exportstarted |
Param { type: Invoked when the Export starts export procedure. You can use event handlers here to modify config before actual export starts. |
#exporttimedout |
Param { type: Invoked when export operation times out. Use Export's |
#inited |
Param { type: Invoked when Export initializes. |
#menucreated |
Param { type: Invoked when Export menu is created. |
Adapters
#backgroundColor |
Param { backgroundColor: |
---|---|
#charset |
Param { charset: |
#container |
Param { container: |
#contentType |
Param { contentType: |
#data |
Param { data: |
#dataFieldName |
Param { field: |
#dataFields |
Param { dataFields: |
#dataFieldsOrder |
Param { dataFieldsOrder: |
#dateFields |
Param { dateFields: |
#dateFormat |
Param { dateFormat: |
#dateFormatter |
Param { dateFormatter: |
#durationFields |
Param { durationFields: |
#durationFormat |
Param { durationFormat: |
#durationFormatter |
Param { durationFormatter: |
#exportFunction |
Param { func: ( type: |
#extraSprites |
Param { extraSprites: |
#filePrefix |
Param { filePrefix: |
#formatDataFields |
Param { dataFields: |
#getCSV |
Param { data: |
#getExcel |
Param { data: |
#getHTML |
Param { data: |
#getJSON |
Param { data: |
#getSVG |
Param { data: |
#isDateField |
Param { field: |
#isDurationField |
Param { field: |
#isNumberField |
Param { field: |
#normalizeSVG |
Param { data: |
#numberFields |
Param { numberFields: |
#numberFormat |
Param { numberFormat: |
#numberFormatter |
Param { numberFormatter: |
#options |
Param { options: |
#pdfmakeDocument |
Param { doc: |
#pdfmakeTable |
Param { options: |
#sprite |
Param { sprite: |
#supported |
Param { options: |
#svgToDataURI |
Param { data: |
#timeoutMessage |
Param { message: |
#title |
Param { options: |
#validateSprites |
Param { validateSprites: |
#xlsxSheetName |
Param { name: |
#xlsxWorkbook |
Param { options: @since 4.9.28 |
#xlsxWorkbookOptions |
Param { options: |