Accepted answer

I know this is a duplicate but I can't find one that matches so...

Never do a blind selectAll by element name:


There are other rect elements within your SVG that are being included causing strange behavior. Instead do:


This targets the selection to what you are really binding your data to.

Updated plunker.

Related Query

More Query from same tag