Capture a div as an image

MarGa picture MarGa · Dec 5, 2012 · Viewed 25.1k times · Source

I have some div tags containing charts rendered by javascript. I want to export them in an image format by the press of a button. I don't know if it's possible to capture a div tag as an image using javascript ! so there i'm asking for tips and hints. Thanks in advance.

Answer

Wutz picture Wutz · Dec 5, 2012

You can create an image using the canvas element. If your charts are rendered using HTML elements you need to draw that HTML onto the canvas. Then you can use toDataURL on the canvas to get the B64-encoded image data.