【问题标题】:d3js - Create a server side SVG with javascript actionsd3js - 使用 javascript 操作创建服务器端 SVG
【发布时间】:2019-04-08 07:47:30
【问题描述】:

我正在尝试启用 javascript 代码,该操作绑定到使用 d3@3 在 NodeJS 中创建的 SVG 元素的操作。 不幸的是,on('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>

on('click') 在哪里??

【问题讨论】:

    标签: javascript node.js d3.js


    【解决方案1】:

    设置

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

    为你点击

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

    【讨论】:

      猜你喜欢
      • 2018-10-04
      • 2018-03-15
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-22
      • 2011-11-15
      • 2016-12-10
      相关资源
      最近更新 更多