Skip to content

Stacked Area ​

The unemployed by industry over time, stacked with cm.stackY, with a legend of the industries on the right, one per line, in a right margin that fits it (guides). After Observable Plot.

js
const data = await d3.csv("/data/bls-industry-unemployment.csv", d3.autoType);

const renderer = cm.svg({width: 640, height: 400});
const root = cm.flow().renderer(renderer);

root
  .data(data)
  .transform(cm.encode, {x: "date", y: "unemployed", fill: "industry"})
  .transform(cm.stackY)
  .transform(cm.plane, {y: {grid: true}, fill: {legend: "right"}})
  .add(cm.areaY);

root.render();
document.body.append(renderer.node());