d3js-使用javascript操作创建服务器端SVG



我正在尝试使用d3@3.遗憾的是,未渲染启用("click"(。

router.get('/test', function(req, res) {
const dom = new JSDOM();
var svg = d3.select(dom.window.document.body)
.append("svg")
.attr("xmlns", "http://www.w3.org/2000/svg")
svg.insert('rect') 
.attr("width", 200)
.attr("height", 200)
.on('click', function() { console.log('click')});
svgStr = dom.window.document.body.innerHTML;
res.set('Content-Type', 'image/svg+xml');
res.send(svgStr);
})

输出:

<svg xmlns="http://www.w3.org/2000/svg"><rect width="200" height="200"> 
</rect></svg>

开着的在哪里??

设置

`
//...
.attr("height", 200)
.attr("onclick" , "console.log('click')")`

点击

并且不允许从图像到页面的记住操作

最新更新