【问题标题】:Insert some texts into D3 Rect element在 D3 Rect 元素中插入一些文本
【发布时间】:2017-08-25 04:25:14
【问题描述】:

/**************************************************** ***/

已删除问题

对不起,耽误了你的时间。

/**************************************************** ***/

【问题讨论】:

  • 你没有向我们展示你在这里尝试了什么,没有文字,所以我们看不到你做错了什么,因此建议需要纠正什么。

标签: javascript html angular d3.js


【解决方案1】:

下次编辑您的代码并使用 sn-p 以便其他人可以清楚地看到 明白你的意思

d3.select('body').append('svg')
//group it
  .append('g').attr('class','test')
  .append('rect')
                                         
                                        .attr('abc','testd3')
                            
                                        .attr('class', 'crew-duty-')
                                        .attr('x',30)
                                        .attr('y', 80)
                                        .attr('width', 100) 
                                        .attr('height', 20)
                                        .attr('fill', 'blue')
                                        .attr('ng-show', true)
                                        .attr('tooltip-type','crewRotationTooltip')
                                        //.on("click")
                                        //.on("mouseover")
                                        //.on("mouseout");

//i dont know what you are aiming for but your code generate this

//insert text on it?
//make group before create react

d3.selectAll('.test').each(function(d,i){

 d3.select(this).append('text')
  .attr('y',95)
  .attr('x',35)
  .attr('text-anchor','left')

   .attr('fill','white')
  .text('On -Full Pay')
  
})

//done

//if not you cant, it append on element but not correct appened, it will not show
d3.selectAll('.crew-duty-').each(function(d,i){

 d3.select(this).append('text')
  .attr('y',95)
  .attr('x',35)
  .attr('text-anchor','left')

   .attr('fill','white')
  .text('SOLOLOLO')
  
})
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.min.js"></script>
  
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

</body>
</html>

【讨论】:

    猜你喜欢
    • 2013-05-13
    • 2023-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    相关资源
    最近更新 更多