The exportAs() method exports the Gantt Chart in the specified image format or as an Excel spreadsheet.
Declaration
DayPilot.Gantt.exportAs(format[, options]);Parameters
format("svg"|"png"|"jpeg"|"xlsx") - output image formatoptions.area("viewport"|"full"|"range") - exported area; defaults to"viewport"options.dateFrom- start date (applies only toarea: "range")options.dateTo- end date (applies only toarea: "range")options.resourceFrom- start task (vertically, applies only toarea: "range")options.resourceTo- end task (vertically, applies only toarea: "range")options.quality- quality of the output JPEG image (applies only toformat: "jpeg"); defaults to0.92options.scale- output scale factor; defaults to1(use2for 200% size)
Return Value
Returns a DayPilot.Export object that provides the following methods:
toElement()- returns a DOM element with the image (<svg>or<img>)toHtml()- returns the image element as HTMLtoDataUri()- returns a data URI string (SVG or image data)toBlob()- returns aBlobobjectdownload(filename)- forces download of the imageprint()- prints the exported image using the browser print dialog
JavaScript
const image = gantt.exportAs("png", {
area: "viewport",
scale: 2
});
image.download("gantt.png");Angular
Use a template reference and ViewChild in an existing component. Invoke exportImage() from a button after initialization.
<daypilot-gantt [config]="config" #gantt></daypilot-gantt>@ViewChild("gantt") gantt!: DayPilotGanttComponent;
config: DayPilot.GanttConfig = {};
exportImage() {
this.gantt.control.exportAs("png", {area: "full", scale: 2}).download("gantt.png");
}React
const gantt = useRef(null);
function exportImage() {
gantt.current.exportAs("png", {area: "full", scale: 2}).download("gantt.png");
}
<DayPilotGantt
controlRef={control => { gantt.current = control; }}
/>Vue
<script setup>
import {ref} from "vue";
const gantt = ref(null);
function exportImage() {
gantt.value.control.exportAs("png", {area: "full", scale: 2}).download("gantt.png");
}
</script>
<template>
<DayPilotGantt ref="gantt" />
</template>Keep the component’s existing date, data and layout options. Angular imports ViewChild and the DayPilot component type; React imports useRef. Vue uses the DayPilot component already registered or imported by the application.
Bitmap Export Errors
PNG and JPEG export can throw an error with name: "DayPilot.ExportError" and code: "BITMAP_EXPORT_FAILED" if the bitmap cannot be created or encoded. This is a structured error object, not a public constructor.
stage:"dimensions","allocation","drawing"or"encoding"format: output MIME typewidth,height,scale: requested logical dimensions and scalepixelWidth,pixelHeight: requested bitmap dimensionssurface:"main"or"group";surfaceWidthandsurfaceHeight: dimensions of the failed surfacecause: optional underlying error
Native canvas SecurityError exceptions keep their original identity. Image and font loading must be handled separately. The exporter does not automatically reduce scale or paginate a large image; choose a smaller area or scale when appropriate.
See Also
Client-Side Image Export [doc.daypilot.org]
Availability
Availability of this API item in DayPilot editions:
| Product | Lite | Pro |
|---|---|---|
| DayPilot for JavaScript |
DayPilot