[D3] Add label text
2024-08-31 15:53:35
If we want to add text to a node or a image
// Create container for the images
const svgNodes = svg
.append('g')
.attr('class', 'nodes')
.selectAll('circle')
.data(d3.values(nodes))
.enter().append('g'); // Add image to the nodes
svgNodes
.append('image')
.attr('xlink:href', d => `/static/media/${d.name.toLowerCase()}.png`)
.attr('x', -25)
.attr('y', -25)
.attr('height', 50)
.attr('width', 50);
// Add text
svgNodes
.append("text")
.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.attr('y', -30)
.attr('class', 'label')
.text(d => d.name);
.label {
pointer-events: none;
font: 8px sans-serif;
text-transform: uppercase;
color: black;
}
最新文章
- MySql类似Oracle的dual虚拟表
- 【krpano】krpano xml资源解密(破解)软件说明与下载
- Eclipse界面设置与常用技巧
- TCP协议下大数据传输IOCP乱序问题
- 团队冲刺the first day
- Remove Element,Remove Duplicates from Sorted Array,Remove Duplicates from Sorted Array II
- 论山寨手机与Android联姻 【8】 自己动手做XP手机
- MySQL的四种事务隔离级别
- 01-artDialog4.1.7常用整理
- WAMP下配置FCGID+ZendGuardLoader
- [Swift]LeetCode684. 冗余连接 | Redundant Connection
- Insertion Sort 与 Merge Sort的性能比较(Java)
- iOS多图上传
- Django路由分配及渲染
- 自己总结的C#编码规范--5.如何写好注释篇
- 服务发现:Zookeeper vs etcd vs Consul 参考自http://dockone.io/article/667
- nodepad++ 正则 替换
- 查准与召回(Precision &; Recall)
- 怎么把<;li>;标签里的内容付给文本框
- [CENTOS7] 修改机器名:hostnamectl set-hostname host.domain