score:2

Accepted answer

you should draw the lines based on data. that's the whole point of d3 (and it's usually faster).

i'm not sure how you draw the chart, there's no relevant code in the question, but...

if you were able to display individual stacks (i'm assuming you want to display lines on top of stacks, which are collections of rectangles), then you should have no problem displaying lines on top of them.

without looking at your data, i can only guess... but here's the basic algorithm:

  1. iterate over the number of stacks
  2. calculate the sum of values of individual elements within each stack
  3. draw lines with y values at those sums (scaled with your chart's yscale)

Related Query