2

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MarGa
  • 711
  • 3
  • 10
  • 23

5 Answers5

2

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.

Wutz
  • 2,246
  • 13
  • 15
0

This is not possible using only JavaScript.

JavaScript has no access on a PC to save files, nor can it convert the DOM to a image format.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
0

There was a dissussion here: html5: copy a canvas to image and back Also there is a project http://www.nihilogic.dk/labs/canvas2image/

Community
  • 1
  • 1
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
0

u might try phantomjs, http://phantomjs.org/, although I have'nt used it personally, but it is widely used for screen captures

Fr0g
  • 252
  • 1
  • 9
0
  1. JS can't access to displayed in case he can't parse HTML
  2. You can call some utility to make screenshot of area. But it's not safe to use, so it will work if you give access.
  3. This question was already asked here. Probably it has some good things you need
Community
  • 1
  • 1
Sugar
  • 490
  • 9
  • 22