Agent-readable demo data

Title
JavaScript Gantt Chart | DayPilot Pro for JavaScript Demo
Tree
DayPilot JavaScript Demo
Catalog root
Default
Description
Read more about the Gantt chart client-side image export.

Inline demo script 1

const dp = new DayPilot.Gantt("dp", {
            days: 30,
            columns: [
                {
                    title: "Name",
                    width: 50,
                    property: "text"
                },
                {
                    title: "Info",
                    width: 50,
                    property: "info"
                },
                {
                    title: "Duration",
                    width: 50
                }
            ],
            onBeforeRowHeaderRender: function (args) {
                const duration = args.task.duration();
                const html = duration.toString("d") + "d " + duration.toString("h") + "h";
                args.row.columns[2].html = html;
            },
            separators: [
                {
                    color: "red",
                    location: DayPilot.Date.today().addDays(1),
                    layer: "BelowEvents"
                }
            ]
        });
        const app = {
            elements: {
                area: document.getElementById("area"),
                downloadButton: document.getElementById("download-button"),
                exportButton: document.getElementById("export-button"),
                preview: document.getElementById("export")
            },
            init() {
                this.loadTaskData();
                dp.init();
                this.addEventHandlers();
            },
            addEventHandlers() {
                this.elements.exportButton.addEventListener("click", ev => {
                    ev.preventDefault();
                    this.showExport();
                });
                this.elements.downloadButton.addEventListener("click", ev => {
                    ev.preventDefault();
                    this.download();
                });
            },
            createExport() {
                const area = this.elements.area.value;
                const options = {area};
                return dp.exportAs("png", options);
            },
            showExport() {
                const image = this.createExport();
                const element = image.toElement();
                element.style.height = `${image.dimensions().height}px`;
                element.style.width = `${image.dimensions().width}px`;
                this.elements.preview.replaceChildren(element);
            },
            download() {
                this.createExport().download();
            },
            loadTaskData() {
                // Generate and load sample tasks.
                let start = new DayPilot.Date().getDatePart();
                let last = null;
                for (let i = 0; i < 5; i++) {
                    const duration = Math.floor(Math.random() * 3) + 1; // 1 to 3
                    const end = start.addDays(duration);
                    const e = new DayPilot.Task({
                        start: start,
                        end: end,
                        id: DayPilot.guid(),
                        text: "Task " + i,
                        tags: {
                            info: "info text"
                        },
                        children: [
                            {start: start, end: end, id: DayPilot.guid(), text: "Subtask 1", complete: Math.floor(Math.random() * 101)},
                            {start: start, end: end, id: DayPilot.guid(), text: "Subtask 2", complete: Math.floor(Math.random() * 101)},
                            {start: end, id: DayPilot.guid(), text: "Milestone 1", type: "Milestone"}
                        ]
                    });
                    dp.tasks.add(e);
                    if (last) {
                        dp.links.add(new DayPilot.Link({
                            id: DayPilot.guid(), // optional
                            from: last,
                            to: e.id(),
                            type: "FinishToStart"
                        }));
                    }
                    last = e.id();
                    start = end;
                }
            }
        };
        app.init();