使用d3在svg g元素中绘制多个项目
我想画三个不同的形状收集在一个g元素。我想画文字、线条和图表。我在下面的代码中遇到的问题是显示了文本,但没有显示行。它是绘制的,我可以在源代码中看到它,但它在屏幕上不可见。我错过了什么使用d3在svg g元素中绘制多个项目,svg,d3.js,Svg,D3.js,我想画三个不同的形状收集在一个g元素。我想画文字、线条和图表。我在下面的代码中遇到的问题是显示了文本,但没有显示行。它是绘制的,我可以在源代码中看到它,但它在屏幕上不可见。我错过了什么 //Bind data to a new g element line = svg.selectAll("g") .data(source) .enter() .append("g") .attr({ "transform": function(d,i){ return "tran
//Bind data to a new g element
line = svg.selectAll("g")
.data(source)
.enter()
.append("g")
.attr({
"transform": function(d,i){ return "translate(50 " + (height - 50 + 15 * i) + ")"}
});
line.append("text")
.text(function(d,i){
return d.name;
});
line.append("line")
.attr({
"opacity" : 1,
"stroke-width" : 2,
"stroke" : "blue",
"class" : "crisp",
"x1" : function (d) { return vfTimelineScale(d.start); },
"y1" : function (d,i) { return (height - 50 + 15 * i); },
"x2" : function (d) { return vfTimelineScale(d.stop); },
"y2" : function (d,i) { return (height - 50 + 15 * i); },
})
您已经通过转换进行了定位,我假定您不需要将行与文本垂直偏移
450
px。将公式更改为诸如
"x1" : function (d) { return vfTimelineScale(d.start); },
"y1" : 50,
"x2" : function (d) { return vfTimelineScale(d.stop); },
"y2" : 50
当然,您需要更改
50
值以满足您的需要。是x1
,y1
,x2
,y2
值,您期望的值是什么?A-模块这是打印出来的。