Download PDF
author(s):
Torstein Hønsi
by Ayyappan Sakthivadivel
HTML
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css">
<script src="https://code.highcharts.com/gantt/highcharts-gantt.js"></script>
<script src="https://code.highcharts.com/gantt/modules/exporting.js"></script>
<div id="container"></div>
<div id="button-container">
<button id="pdf">
<i class="fa fa-download"></i> Download PDF
</button>
</div>
CSS
#container, #button-container {
max-width: 800px;
margin: 1em auto;
}
#pdf {
border: 1px solid silver;
border-radius: 3px;
background: #a4edba;
padding: 0.5em 1em;
}
#pdf i {
margin-right: 1em;
}
JavaScript
Highcharts.ganttChart('container', {
title: {
text: 'Highcharts Gantt Chart'
},
yAxis: {
uniqueNames: true
},
exporting:{
buttons: {
contextButton: {
title: "contextButtonTitle",
symbolSize: 16,
symbolY: 15,
menuItems: ["downloadPNG", "downloadJPEG", "downloadPDF", "downloadSVG"],
_titleKey: "Download"
}
}
},
series: [{
name: 'Project 1',
data: [{
start: Date.UTC(2018, 11, 1),
end: Date.UTC(2018, 11, 2),
completed: 0.95,
name: 'Prototyping'
}, {
start: Date.UTC(2018, 11, 2),
end: Date.UTC(2018, 11, 5),
completed: 0.444,
name: 'Development'
}, {
start: Date.UTC(2018, 11, 8),
end: Date.UTC(2018, 11, 9),
completed: 0.141,
name: 'Testing'
}, {
start: Date.UTC(2018, 11, 9),
end: Date.UTC(2018, 11, 19),
completed: {
amount: 0.3,
fill: '#fa0'
},
name: 'Development'
}, {
start: Date.UTC(2018, 11, 10),
end: Date.UTC(2018, 11, 23),
name: 'Testing'
}]
}]
});
// Activate the custom button
document.getElementById('pdf').addEventListener('click', function () {
Highcharts.charts[0].exportChart({
type: 'application/pdf'
});
});