【问题标题】:D3 Pie Chart rotate only the arcsD3饼图仅旋转弧线
【发布时间】:2020-10-16 17:27:12
【问题描述】:

我的图表需要在甜甜圈的中心有一个标签,点击时不应旋转。

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.js


    【解决方案1】:

    我通过反向旋转我的文字找到了解决方案。我最大的障碍就是在 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) + ")");
    

    【讨论】:

      猜你喜欢
      • 2021-08-02
      • 2011-12-24
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多