svg里面文本是text ,x是文字左边的,y是文字下面的数值。添加文本内容。
svg.append("text")
.text("text");
<text x="50" y="13" style="fill: red; text-anchor: end">
文字右对齐的属性是 text-anchor
rsvg里面添加数据
var colorBar=function(){
svg.selectAll("rect")
.data(colorbrew)
.enter()
.append("rect")
.attr("width",20)
.attr("height",20)
.attr("x",function(d,i){ return 320+i*20;})
.style("color",function(d){ return d});
如果想要把d和相应的dom节点对应起来,可以实现存dom的节点,然后让键为d的id值,在d3的联级的时候,this可以存储当前dom值。
nodeEnter.append("circle")
.style("fill", function (d) {
circles[d.id] = this;
return color[d.id]
})
;
哦,不过在交互的时候,直接把this传进去也还好。
.on("mouseover",function(d){
//console.log(" 194 rect mouseover"+d.id);
node_onMouseOver(d,this);
})
mouseout