d3.js - D3饼图只旋转弧线
问题描述
我的图表需要在甜甜圈中心有一个标签,单击时不应旋转。
https://codepen.io/scratchy303/pen/dyXMzrz
我可以在同级“g”组中附加标签并旋转弧组吗?我可以只翻译圆弧而不是旋转整个 SVG 吗?最简单的解决方案是什么?
var svg = d3.select("#pieChart").append("svg")
.attr("width", '100%')
.attr("height", '100%')
.attr('viewBox', '0 0 ' + Math.min(width, height) + ' ' + Math.min(width, height))
.attr('preserveAspectRatio', 'xMinYMin')
.append("g")
.attr("transform", "translate(" + radius + "," + height / 2 + ")")
.style("filter", "url(#drop-shadow)");
svg.append("g")
.append("text")
.attr("text-anchor", "middle")
.text("Donut Name");
解决方案
我通过反向旋转我的文字找到了解决方案。我最大的障碍就是在 D3 中遍历我的 SVG。
//start by selecting the parent "g"roup and then you can select the text
d3.select(i.parentNode).select(".donut-label")
.transition()
.duration(1000)
.attr("transform", "rotate(" + (-angle) + ")");
推荐阅读
- verilog - Questa Sim 中的 assign 语句产生 x 作为输出
- flutter - 视频播放器颤振的基本界面
- php - Laravel如何检查和避免控制器中的重复条目
- java - 如何单击 ::before 和 ::after 内的元素
- python - 如何有效地从另一个数组中删除一个数组的元素
- apache - 针对 Apache 和 Liferay 重定向问题的 Docker Compose
- mysql - MySQL 上的 Flask SQLAlchemy pool_pre_ping 根本不工作
- python - 获取从数组到变量的所有内容
- reactjs - 检查路由是否有效反应路由器
- c# - c# 中的高级元编程是否有一些行业“标准”?