Print large Raphael JS chart accross multiple pages

旧时模样 提交于 2019-12-11 20:52:12

问题


I have a large chart produced with Raphael, that I want to display in a printer-friendly page. With smaller charts this works beautifully even down to IE7 (min requirement).
But if the chart is too long vertically it doesn't split across pages, instead the bottom is just cut off; this happens in all browsers.

Any suggestions as to how I might solve this problem? Preferably without just making it smaller.

Thanks


回答1:


What you want to achieve is not directly possible. Raphael container element marks overflow:hidden style and as such for browsers that considers partial page split as overflow, it would be very difficult to split the output - especially if the overflow is horizontal.

As a workaround, you may convert Raphael's SVG into canvas by using the canvg JS library. Canvas, being a single raster element, will allow seamless overflow.

You can have a look at this fiddle where I use FusionCharts' (internally using Raphael) SVG to output to a canvas.

canvg("myCanvasElementId", myRaphaelPaper.canvas.parentNode.innerHTML);

In the above code snippet, I assume that you already have a canvas element with id myCanvasElementId and a Raphael paper called myRaphaelPaper.

Refer to this fiddle where I have rendered Raphael SVG and exported it to canvas and then made it visible only for CSS print media. The Raphael element is made to render 15in by 15in to overflow document.

Note that this will be limited to modern browsers supporting canvas.



来源:https://stackoverflow.com/questions/18085854/print-large-raphael-js-chart-accross-multiple-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!