使用d3js

时间:2015-10-26 02:32:50

标签: javascript html d3.js svg

嗨所以我正在尝试将多个文本元素添加到d3 svg g节点。但是,对于以下代码,节点的所有第一个文本分配都会显示,但不会显示第二个文本元素。我的做法是对的吗?或者是否有我错过的错误

 var node = svg.selectAll("g.node")
  .data(nodes, function(d) { return d.id || (d.id = ++i); });

 // Enter any new nodes at the parent's previous position.
 var nodeEnter = node.enter().append("g")
  .attr("class", "node")
  .attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
  .on("click", click);

nodeEnter.append("circle")
  .attr("r", 1e-6)
  .style("fill", function(d) { return d._children ? "lightsteelblue" : "#fff"; });
  // .on("mouseenter",setdatavis)
  // .on("mouseleave",setdatainvis);

nodeEnter.append("text")
  // .attr("x",0)
  // .attr("y",0)
  // .append("tspan")
  .attr("x", function(d) { return d.children || d._children ? -10 : 10; })
  .attr("y",-10)
  .attr("dy", ".35em")
  .attr("text-anchor", "end")
  .text(function(d) { return d.name; })
  .style("fill-opacity", 1e-6)
  .style("visibility","visible");
  // .on("mouseenter", function(){d3.select(this)
  //   .style("visibility", "hidden")
  //   .transition()                      
  //   ;})
  // .on("mouseleave", function(){d3.select(this)
  //   .style("visibility", "visible")
  //   .transition()                      
  //   ;});

nodeEnter.append("text")
  .attr("x",10)
  .attr("text-anchor","start")
  .attr("y",10)
  .attr("dy",".35em")
  .text(function(d){return "hi";})
  .style("visibility","visible")
  .style("fill-opacity",1e-6);

0 个答案:

没有答案