Stacked bar charts stack comparable quantities together for a given category, allowing the viewer to compare the totals and how each quantity contributes to each total. Stacked area charts and steamgraphs are frequently used to display cumulative data over time.
To create a stack, it's necessary to move bars or areas so that one shape is rendered on top of the other. The stack layout generator in D3 takes a dataset and returns a new data structure containing computed positions that can be used to stack bars or to set the top (y1) or bottom (y0) lines in an area function.
A stack layout generator is created with d3.stack():
const stack = d3.stack();
Configure the function with keys (or array indexes) that select the series that should be stacked, and then call it with the data:
const data = [ [190, 90, 150],
[330, 160, 275],
[390...