vis.js网络拓扑图下载、导出png图片(canvas导出图片)

1.首先看效果图:

vis.js网络拓扑图下载、导出png图片(canvas导出图片)_第1张图片

2.代码部分:

html:

js:

//todo 给canvas加个id,下载图片的时候要用到,要放在new vis.Network(container, data, options);后面,不然拿不到值
 $("#mynetwork canvas").attr("id","canvas");
/**
* 下载图片
*/
$("#loadPng").on('click',function () {
   var mynetworkCanvas = document.getElementById("canvas");
   console.log('mynetworkCanvas',mynetworkCanvas);
   mynetworkCanvas.toBlob(function(blob) {
       var a = document.createElement("a");
       document.body.appendChild(a);
       a.download = "network" + ".png";
       a.href = window.URL.createObjectURL(blob);
       a.click();
    });
});

3.完整代码:




    
    
    
    vis图片下载
    
    

    
    
    



4.参考地址:https://blog.csdn.net/qq_27870421/article/details/89409633

你可能感兴趣的:(vis.js,vis.js,vis.js图片下载,vis.js导出png图片,canvas导出图片,canvas图片下载)