How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?

后端 未结 6 1013
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 19:50

I currently have a website using D3 and I\'d like the user to have the option to save the SVG as an SVG file. I\'m using crowbar.js to do this, but it only works on chrome.

6条回答
  •  一生所求
    2020-11-28 20:14

    For this snippet to work you need FileSaver.js.

    function save_as_svg(){
    
    
            var svg_data = document.getElementById("svg").innerHTML //put id of your svg element here
    
            var head = ''
    
            //if you have some additional styling like graph edges put them inside "
            var blob = new Blob([full_svg], {type: "image/svg+xml"});  
            saveAs(blob, "graph.svg");
    
    
    };
    

提交回复
热议问题