Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Morris Graphs Export as PDF?

I am using Morris.js to create graphs. I have requirement to export graphs as pdf. I can see that graphs are svg elements. What should i do to achieve this.

like image 912
sushil bharwani Avatar asked Aug 05 '26 17:08

sushil bharwani


1 Answers

I took one of the Morris samples and made a fiddle for you:

http://jsfiddle.net/1roLdqte/48/

I added a simple call to format to PDF the existing div with just the morris chart:

$('#print').click(function () {
printMe();
});
function printMe() {
  xepOnline.Formatter.Format('line-example',{render:'download', srctype:'svg'});
 }

Run the fiddle and push the PDF button.

Note there are many more parameters available here, you can format much more content than just the morris.js chart, control page sizes, add header/footers and such. This only formats the chart alone (srctype:'svg') to PDF as a vector image (not raster).

like image 163
Kevin Brown Avatar answered Aug 08 '26 09:08

Kevin Brown