javascript – d3.js:如何为图表上的散点图添加标签

前端之家收集整理的这篇文章主要介绍了javascript – d3.js:如何为图表上的散点图添加标签前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将标签添加到此图表上的散点图: http://bost.ocks.org/mike/d3/workshop/dot-chart.html

我认为稍微修改这段代码会起作用,但它没有:

svg.selectAll(".dot")
  .append("text")
  .text("fooLabelsOfScatterPoints");

解决方法

迈克罗宾逊,你的榜样帮了忙.

对于那些想知道的人,这就是我所做的:

删除了:

svg.selectAll(".dot")
  .data(data)
  .enter().append("circle")
  .attr("class","dot")
  .attr("cx",function(d) { return x(d.x); })
  .attr("cy",function(d) { return y(d.y); })
  .attr("r",12);

并补充说:

var node = svg.selectAll("g")
                .data(data)
                .enter()
                .append("g");

node.append("circle")
  .attr("class",12);

node.append("text")
  .attr("x",function(d) { return x(d.x); })
  .attr("y",function(d) { return y(d.y); })
  .text("fooLabelsOfScatterPoints");

我将“text”标签添加到“g”标签上,而不是将“text”标签附加到“circle”标签上.

原文链接:https://www.f2er.com/js/159140.html

猜你在找的JavaScript相关文章