You must be logged in to post your query.
Home › Forums › Chart Support › Export CanvasJS to PDF
Tagged: download, export, pdf, Theme
Hi Team,
I want to download the CanvasJS chart as a PDF. I used jsPDf as u referred in jsfiddle.
But the problem is I have rendered the chart in a dark theme. But I want the chart in a light theme when I try to download. Is there any option to update the chart theme dynamically before the download start? I don’t want any change in the application, it should be in a dark theme. Just need a light theme on the PDF.
Please give me a solution to export the chart in a light theme and maintain the dark theme on the web page.
Thanks Ragu
Ragu,
To export the chart in a pdf with a light theme, you can use chart.set() to change the theme to light1 or light2 right before fetching the base64 image of the chart as shown in the code-snippet below,
light1
light2
$("#exportButton").click(function(){ var pdf = new jsPDF(); var chartTheme = chart.get("theme"); chart.set("theme", "light2"); var canvas = $("#chartContainer .canvasjs-chart-canvas").get(0); var dataURL = canvas.toDataURL(); chart.set("theme", chartTheme); pdf.addImage(dataURL, 'JPEG', 0, 0); pdf.save("download.pdf"); });
Kindly take a look at this JSFiddle for an example on the same with complete code.
Thank you so much for the prompt reply. I get the idea now.
Awesome plugin and works very well!
You must be logged in to reply to this topic. Login/Register