Truncate text in d3

后端 未结 1 1668
谎友^
谎友^ 2021-01-18 07:17

I want to truncate text that is over a predefined limit in d3.

I\'m not sure how to do it.

Here\'s what I have now:

  node.append(\"text\         


        
相关标签:
1条回答
  • 2021-01-18 08:13

    To truncate text use substring

    Try this code:

    DEMO

     .text(function (d) {
         if(d.name.length > 5)
             return d.name.substring(0,5)+'...';
         else
             return d.name;                       
     });
    
    0 讨论(0)
提交回复
热议问题