读取d3文本元素的宽度 [英] read width of d3 text element

查看:1610
本文介绍了读取d3文本元素的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取在创建d3后创建的< text> 元素的宽度。



我尝试过

  svg.selectAll(text)
。 {
console.log('text',d3.select(this).style(width));
}); //'auto'

  svg.selectAll(text)
.each(function(){
console.log('text',$(this).css ));
}); //0px

提前感谢

  this.getComputedTextLength )。 

在一个元素的选择中,您可以说

  selection.node()。getComputedTextLength()。 

您也可以使用 getBBox

I would like to read the width of <text> elements, created in d3, after they're created.

I have tried

svg.selectAll("text")
    .each(function () {
        console.log('text', d3.select(this).style("width"));
    }); // 'auto'

and

svg.selectAll("text")
    .each(function () {
        console.log('text', $(this).css("width"));
    }); // '0px'

Thanks in advance

解决方案

In a selection method (such as attr) :

   this.getComputedTextLength(). 

In a selection of one element, you can say

   selection.node().getComputedTextLength(). 

You can also use getBBox for the width and height

这篇关于读取d3文本元素的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆