简体   繁体   English

将一些文本插入D3 Rect元素

[英]Insert some texts into D3 Rect element

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

deleted question 删除的问题

I'm sorry for took time of you. 很抱歉花了你很多时间。

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

Next time edit your code and use snippet so other can clearly understand what you means 下次编辑您的代码并使用代码段,以便其他人可以清楚地理解您的意思

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM