Scale Up Chart Size Before Exporting Chart and Reset it - CanvasJS JavaScript Charts
Scale Up Chart Size Before Exporting Chart and Reset it - CanvasJS JavaScript Charts
by canvasjs
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/>
<!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
<button id="printChart">Export Chart</button>
JavaScript
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2",
title: {
text: "Scaleup Chart Size before Exporting"
},
data: [{
type: "column",
dataPoints: [
{ label: "apple", y: 10 },
{ label: "orange", y: 15 },
{ label: "banana", y: 25 },
{ label: "mango", y: 30 },
{ label: "grape", y: 28 }
]
}]
});
chart.render();
document.getElementById("printChart").addEventListener("click", function() {
var width = chart.get("width");
var height = chart.get("height");
chart.set("width", width * 2);
chart.set("height", height * 2);
chart.exportChart({ format: "jpg" });
chart.set("height", height);
chart.set("width", null);
});