jQWidgets Forums
jQuery UI Widgets › Forums › Chart › Exporting chart to image and get the src of image › Reply To: Exporting chart to image and get the src of image
Hi Stanilav,
Thanks for the response. Actually, the export example downloads the PNG image to the browser.Now, my chart is dynamic and will change whenever user changes data. Hence, I think downloading image and hard coding file path to reference it in PDF doesn’t seem right.
Is there any way to programmatically convert chart to canvas element or a data-url? This is one such example from Chart.js to illustrate what I would require. JSFiddle link is given.
http://jsfiddle.net/canvasjs/cm1qyk2L/
var chart = new CanvasJS.Chart("chartContainer",
{
title: {
text: "Exporting chart using jsPDF & toDataurl"
},
data: [
{
type: "spline",
dataPoints: [
{ x: 10, y: 4 },
{ x: 20, y: 7 },
{ x: 30, y: 2 },
{ x: 40, y: 3 },
{ x: 50, y: 5 }
]
}
]
});
chart.render();
var canvas = $("#chartContainer .canvasjs-chart-canvas").get(0);
var dataURL = canvas.toDataURL();
//console.log(dataURL);
$("#exportButton").click(function(){
var pdf = new jsPDF();
pdf.addImage(dataURL, 'JPEG', 0, 0);
pdf.save("download.pdf");
});