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

More Query from same tag