I ended up using rect
regions instead as shaded areas in preference to lines. However, returning to this I realised that the code is almost the same for drawing a series of rectangles vs. a series of straight lines. The confusion was arising from the d3 function .line()
which is used to generate a path
. However you can create a series of straight lines by using svg:line
and passing data via a generator function (here wrapped in a dictionary):
var line = {
'x1':(function(d) { return x( labl.x ); }),
'y1':(function(d) { return y( maxY ); }),
'x2':(function(d) { return x( labl.x ); }),
'y2':(function(d) { return y( minY) }),
}
var label = svg.selectAll(".labels")
.data(labels)
.enter();
label.append("svg:line")
.attr("x1", line.x1)
.attr("y1", line.y1)
.attr("x2", line.x2)
.attr("y2", line.y2)
.attr("class","label-line");