Agent-readable demo data
- Title
- SVG Image Export (JavaScript Scheduler) | DayPilot Pro for JavaScript Demo
- Tree
- DayPilot JavaScript Demo
- Catalog root
- Default
- Description
- Read more about client-side SVG export.
Inline demo script 1
const dp = new DayPilot.Scheduler("dp", {
startDate: "2026-01-01",
days: 365,
scale: "Day",
timeHeaders: [
{groupBy: "Month", format: "MMMM yyyy"},
{groupBy: "Cell", format: "d"}
],
treeEnabled: true,
resources: [
{
name: "Locations", id: "G1", expanded: true, children: [
{name: "Room 1", id: "A"},
{name: "Room 2", id: "B"},
{name: "Room 3", id: "C"},
{name: "Room 4", id: "D"}
]
},
{
name: "People", id: "G2", expanded: true, children: [
{name: "Person 1", id: "E"},
{name: "Person 2", id: "F"},
{name: "Person 3", id: "G"},
{name: "Person 4", id: "H"}
]
},
{
name: "Tools", id: "G3", expanded: true, children: [
{name: "Tool 1", id: "I"},
{name: "Tool 2", id: "J"},
{name: "Tool 3", id: "K"},
{name: "Tool 4", id: "L"}
]
},
],
height: 300,
});
dp.init();
const app = {
init() {
this.bindEvents();
this.loadEventData();
},
loadEventData() {
const events = [];
for (let i = 0; i < 12; i++) {
const duration = Math.floor(Math.random() * 6) + 1; // 1 to 6
const durationDays = Math.floor(Math.random() * 6); // 0 to 5
const start = Math.floor(Math.random() * 6) + 2; // 2 to 7
events.push({
start: new DayPilot.Date(dp.startDate).addDays(start),
end: new DayPilot.Date(dp.startDate).addDays(start).addDays(durationDays).addHours(duration),
id: DayPilot.guid(),
resource: String.fromCharCode(65 + i),
text: "Event " + (i + 1),
});
}
dp.update({events: events});
},
bindEvents() {
document.getElementById('export-button').addEventListener('click', function(ev) {
ev.preventDefault();
const area = document.getElementById('area').value;
document.getElementById('zoom').style.display = 'block';
const e = dp.exportAs('svg', {
area: area,
dateFrom: '2026-01-01',
dateTo: '2026-01-31',
resourceFrom: 'A',
resourceTo: 'D'
});
const element = e.toElement();
element.style.height = e.dimensions().height + 'px';
element.style.width = e.dimensions().width + 'px';
document.getElementById('export').innerHTML = '';
document.getElementById('export').appendChild(element);
});
document.getElementById('download-button').addEventListener('click', function(ev) {
ev.preventDefault();
const area = document.getElementById('area').value;
dp.exportAs('svg', {
area: area,
dateFrom: '2026-01-01',
dateTo: '2026-01-31',
resourceFrom: 'A',
resourceTo: 'D'
}).download();
});
document.getElementById('zoomin').addEventListener('click', function(ev) {
console.log("zoomin");
ev.preventDefault();
const svgElement = document.querySelector('svg');
const height = svgElement.clientHeight;
const width = svgElement.clientWidth;
svgElement.style.height = height * 1.1 + 'px';
svgElement.style.width = width * 1.1 + 'px';
});
document.getElementById('zoomout').addEventListener('click', function(ev) {
ev.preventDefault();
const svgElement = document.querySelector('svg');
const height = svgElement.clientHeight;
const width = svgElement.clientWidth;
svgElement.style.height = height / 1.1 + 'px';
svgElement.style.width = width / 1.1 + 'px';
});
}
};
app.init();