d3.js D3 js bbox未在v7中形成

4ioopgfo  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(169)

我试图在d3js中创建一个bbox,这样它就可以封装我的文本,但它似乎没有形成。

function jobsCreation()
{
        let enteringText = dataJobs
            .enter()
            .append("text")
            .attr("x",function(d){return d.posX})
            .attr("y",function(d){return d.posY})
            .text(function(d){return d.name});

            let bbox = text.nodes().getBBox();

            let rect = svg.append("rect")
            .attr("x", bbox.x)
            .attr("y", bbox.y)
            .attr("width".bbox.width)
            .attr("height",bbox.height)
            .style("fill","#ccc")
            .style("stroke", "black")
            .style("stroke-width", "1.5px");
    }
wljmcqd8

wljmcqd81#

对不起,伙计们,我没有得到适当的数据,他们是我的代码的一些问题,我得到了它的工作现在。
固定代码:

function jobsCreation(){
        let enteringText = dataJobs
            .enter()
            .append("text")
            .attr("x",function(d){return d.posX})
            .attr("y",function(d){return d.posY})
            .text(function(d){return d.name});

            let bbox = enteringText.node().getBBox();

            let rect = svg.append("rect")
            .attr("x", bbox.x)
            .attr("y", bbox.y)
            .attr("width",bbox.width)
            .attr("height",bbox.height)
            .style("fill","white")
            .style("stroke", "black")
            .style("stroke-width", "1.5px");

    }

相关问题