Skip to content

Marimekko ​

Sales by market and segment. Each market's column is as wide as its total sales, with the flex option of cm.spreadX; within it, the segments stack to 100% with offset "normalize". After Observable Plot, without its labels.

js
const sales = await d3.csv("/data/sales.csv", d3.autoType);
const markets = Array.from(new Set(sales.map((d) => d.market)));

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

root
  .data(sales)
  .transform(cm.encode, {
    x: "market",
    y: "value",
    fill: "segment",
    n: "value",
  })
  .transform(cm.spreadX, {flex: "n", padding: 0, domain: markets})
  .transform(cm.stackY, {offset: "normalize"})
  .transform(cm.plane, {x: {label: null}, y: {label: null, tickFormat: "%"}})
  .add(cm.rect, {fillOpacity: 0.5, stroke: "white"})
  .add(cm.annotate(cm.rect), {fill: "none", stroke: "currentColor"});

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