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
var dp = new DayPilot.Gantt("dp");
dp.days = 30;
// generate and load sample tasks
var start = new DayPilot.Date().getDatePart();
var last = null;
for (var i = 0; i < 5; i++) {
var duration = Math.floor(Math.random() * 3) + 1; // 1 to 3
var end = start.addDays(duration);
var 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) // 0 to 100
},
{
start: start,
end: end,
id: DayPilot.guid(),
text: "Subtask 2",
complete: Math.floor(Math.random() * 101) // 0 to 100
},
{
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;
}
dp.columns = [
{
title: "Name",
width: 50,
property: "text"
},
{
title: "Info",
width: 50,
property: "info"
},
{
title: "Duration",
width: 50
}
];
dp.onBeforeRowHeaderRender = function (args) {
var duration = args.task.duration();
var html = duration.toString("d") + "d " + duration.toString("h") + "h";
args.row.columns[2].html = html;
};
dp.separators = [
{
color: "red",
location: DayPilot.Date.today().addDays(1),
layer: "BelowEvents"
}
];
dp.init();
const app = {
init() {
this.addEventHandlers();
},
addEventHandlers() {
document.getElementById("export-button").addEventListener("click", (ev) => {
ev.preventDefault();
const area = document.getElementById("area").value;
const e = dp.exportAs("png", {area: area});
const element = e.toElement();
element.style.height = `${e.dimensions().height}px`;
element.style.width = `${e.dimensions().width}px`;
const exportElement = document.getElementById("export");
while (exportElement.firstChild) {
exportElement.firstChild.remove();
}
exportElement.appendChild(element);
return false;
});
document.getElementById("download-button").addEventListener("click", (ev) => {
ev.preventDefault();
const area = document.getElementById("area").value;
dp.exportAs("png", {area: area}).download();
});
}
};
app.init();