【发布时间】:2016-07-06 19:47:04
【问题描述】:
我正在尝试使我在 d3 中的圆环图中的 <text> 和 <path> 元素可点击,但遇到了一些问题。这是我正在使用的代码:
var g = svg.append('g')
.attr('transform', 'translate(' + width / 2 + ',' + ((height / 2)) + ')');
var arcs = g.selectAll('path');
arcs = arcs.data(pie(formattedData));
arcs.exit().remove();
arcs.enter().append('path')
.style('stroke', 'white')
.attr('fill', function (d, i) { return color(i) });
arcs.attr('d', arc);
arcs.append("text")
.attr("transform", function (d) { return "translate(" + labelArc.centroid(d) + ")"; })
.attr("dy", "0em")
.attr("style", "font-size: 1.5em;")
.attr("fill", "white")
.text(function (d) { return d.value; })
我可以通过直接在开发工具中编辑 DOM 来在 <path> 和 <text> 元素周围添加 <a> 标签,但我不能做 .wrap() 或更改代码以使用它:
.append("a").attr("href", "http://wwww.gooogle.com")
我错过了什么?
【问题讨论】:
-
你是想用 d3 还是 jQuery 来修改图表?
-
我想使用 d3,这样我就可以访问数据并相应地更改每个项目的 href。
-
这个答案可能有你要找的东西:stackoverflow.com/questions/13104681/…
标签: javascript jquery html d3.js