[英]how i get height of a svg element using d3js
i am using d3.js to find the height of an SVG
element with the following code 我正在使用d3.js通过以下代码查找
SVG
元素的高度
<script>
var body = d3.select("body");
console.log(body);
var svg = body.select("svg");
console.log(svg);
console.log(svg.style("height"));
</script>
<svg class="svg" height="3300" width="2550">
<image x="0" y="0" height="3300" width="2550" xlink:href="1.jpg"></image>
<rect class="word" id="15" x="118" y="259" width="182" height="28"
text="Substitute"></rect>
</svg>
but it returned an error 但它返回了一个错误
Uncaught TypeError: Cannot call method 'getPropertyValue' of null
未捕获的TypeError:无法调用null的方法“ getPropertyValue”
You need to load js
after the DOM
is redered. 重新设置
DOM
之后,您需要加载js
。 You can either put the <script></script>
in the bottom of your <body></body>
or have it inside the following javascript
method. 您可以将
<script></script>
放在<body></body>
的底部,也可以将其放在以下javascript
方法中。
document.addEventListener("DOMContentLoaded", function(event) {
//your code here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.