Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simg.js:37 Uncaught TypeError: svg.setAttribute is not a function #15

Open
FlorianLeitgeb opened this issue Jun 5, 2018 · 1 comment

Comments

@FlorianLeitgeb
Copy link

FlorianLeitgeb commented Jun 5, 2018

I have a d3 graph within a svg element and wanted to export it. Just grabbed the svg element and called simg like shown in your example:

function exportToPNG() {
  var simg = new Simg(document.getElementsByTagName("svg"));
  // Replace the current SVG with an image version of it.
  simg.replace();

  // And trigger a download of the rendered image.
  simg.download();
}

simg.js:37 Uncaught TypeError: svg.setAttribute is not a function
    at simg.js:37
    at Array.forEach (<anonymous>)
    at root.Simg.toString (simg.js:36)
    at root.Simg.toSvgImage (simg.js:57)
    at root.Simg.toCanvas (simg.js:44)
    at root.Simg.toImg (simg.js:74)
    at root.Simg.replace (simg.js:90)
    at exportToPNG (itsv.pws.ui.projStruct.js?ver:50)
    at HTMLAnchorElement.onclick (ProjStruct.aspx:1)
@ml-eds
Copy link

ml-eds commented Sep 27, 2018

document.getElementsByTagName("svg") returns an array of matching elements. Use

document.getElementsByTagName("svg")[0]

or

d3.select("svg").node()

to get actual DOM Element instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants