Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript d3.js getBBox().width返回0_Javascript_Jquery_Html_Css_D3.js - Fatal编程技术网

Javascript d3.js getBBox().width返回0

Javascript d3.js getBBox().width返回0,javascript,jquery,html,css,d3.js,Javascript,Jquery,Html,Css,D3.js,我正在使用D3.js创建一个可折叠的树 我在树的文本元素后面附加图像。在追加图像时,我想将节点的宽度设置为image元素的x属性,以便在text元素之后追加图像。我对它使用了getBBox(),但它返回我{x:0,y:0,width:0,height:0} 有没有关于如何进行的建议 有关守则: nodeEnter.append("text").attr("x", function (nodeData) { return nodeData.children || nodeData._childre

我正在使用D3.js创建一个可折叠的树

我在树的文本元素后面附加图像。在追加图像时,我想将节点的宽度设置为image元素的x属性,以便在text元素之后追加图像。我对它使用了getBBox(),但它返回我{x:0,y:0,width:0,height:0}

有没有关于如何进行的建议

有关守则:

nodeEnter.append("text").attr("x", function (nodeData) { return nodeData.children || nodeData._children ? x_pos = -10 : x_pos = 10; })
    .attr("dy", ".35em")
    .attr("text-anchor", function (nodeData) { return nodeData.children || nodeData._children ? "end" : "start"; })
    .text(function (nodeData) { return nodeData.name; })
    .style("fill-opacity", 1e-6);

nodeEnter.data(nodes).filter(function (nodeData) { return nodeData.icon ? nodeData.icon : null; }).append("image")
    .attr("xlink:href", function (nodeData) { return nodeData.icon ? nodeData.icon : null; })
    .attr("x", , function (nodeData) { return d3.select(this.parentNode).node().getBBox().width; )
    .attr("y", "-7px")
    .attr("width", "16px")
    .attr("height", "14px");    

你试过查看以下日志了吗:d3.select(this.parentNode).node()。为什么不直接
this.parentNode.getBBox().width
?@thatonegoy是的。它还给我这个:DD,Number@tarulen我甚至试过你的建议。它也返回0。您必须发布更多的代码或事件,最好将JSFIDLE放在一起,以便我们可以看到它