Home » Javascript » D3js Export SVG to Image

D3js Export SVG to Image

Posted by: admin July 16, 2018 Leave a comment

Questions:

I have this D3js line graph I’m working with.

I’d like to be able to save it as an image in the same directory as shown in this example

d3.select('#saveButton').on('click', function(){
    var svgString = getSVGString(svg.node());
    svgString2Image( svgString, 2*width, 2*height, 'png', save ); // passes Blob and filesize String to the callback

    function save( dataBlob, filesize ){
        saveAs( dataBlob, 'D3 vis exported to PNG.png' ); // FileSaver.js 
function
    }
});

no errors running the above

Although I am getting no errors, the file is not downloading when the button is clicked. What am I missing here? Thanks!

Answers: