This is the code for Chapter 5, Figure 21 from D3.js in Action showing how to use d3.layout.stack() to create a streamgraph.