---
title: "Dot Chart · Playground · Drew Minns"
description: "Data drawn in dither, with colour bands that blend."
url: https://reallygood.work/playground/dot-chart/
---

Playground · 04

# Dot Chart

Data drawn in dither, with colour bands that blend.

Live piece: Sample weekly chart drawn in dithered dots.

Bands

9

Speed

0.35

Fade

0.78

Dot size

2px

Note

How it works

Dense at the line, thinning toward the baseline. No outline: the edge of the dots is the line.

Colour bands roll upward through the dots, and each band dithers into the next instead of stopping hard. Sample data.

```js
// each dot's band is dithered against the next, so bands blend instead of stopping hard
const f = (value / max) * bands * 1.6 - phase;
let band = Math.floor(f);
if (f - band > B8[(y + 3) & 7][(x + 5) & 7]) band++;
```

Make it yourself

The whole thing in one file, with no libraries. Save it as an .html file and open it. The settings at the top follow the controls above, so tune it there, then copy.

dot-chart.html

```html
<!doctype html>
<meta charset="utf-8">
<title>Dot Chart</title>
<style>
  body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #f4f1ea; font-family: ui-monospace, monospace; }
  canvas { width: min(92vw, 960px); aspect-ratio: 2 / 1; }
</style>
<canvas id="chart"></canvas>
<script>
const settings = {
  bands: 9,    // how many colour bands roll up through the dots
  speed: 0.35,    // how fast they roll
  fill: 0.78,      // how quickly the dots thin toward the baseline (0 = solid, 1 = gone at the bottom)
  dot: 2,        // size of one dot, in CSS pixels
  note: 'the March peak',      // a note circled on the peak ('' for none)
};

// 52 weeks of sample data
const data = Array.from({ length: 52 }, (_, i) => Math.max(1, 6 + 8 * Math.exp(-(((i - 10) / 4) ** 2)) + 4.5 * Math.exp(-(((i - 34) / 6) ** 2)) + 1.8 * Math.sin(i * 0.9)));
const max = 20;
const ramp = ['#1f35ff', '#3b8df0', '#ff5fae', '#ff4310', '#dcff2e'].map(h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16)));

// an 8×8 Bayer matrix: a threshold for every pixel, so tone turns into an even pattern of dots
const bayer = n => { let m = [[0]]; while (m.length < n) { const s = m.length; m = Array.from({ length: s * 2 }, (_, y) => Array.from({ length: s * 2 }, (_, x) => 4 * m[y % s][x % s] + [0, 2, 3, 1][(y >= s ? 2 : 0) + (x >= s ? 1 : 0)])); } return m.map(r => r.map(v => (v + 0.5) / (n * n))); };
const B8 = bayer(8);

const mix = (a, b, t) => a.map((v, i) => v + (b[i] - v) * t);
const rampAt = q => { const f = Math.min(1, Math.max(0, q)) * (ramp.length - 1), i = Math.min(ramp.length - 2, Math.floor(f)); return mix(ramp[i], ramp[i + 1], f - i); };
const valueAt = u => { const f = u * (data.length - 1), i = Math.min(data.length - 2, Math.floor(f)), t = f - i; return data[i] * (1 - t) + data[i + 1] * t; };

const canvas = document.getElementById('chart'), ctx = canvas.getContext('2d');
const pix = document.createElement('canvas'), pctx = pix.getContext('2d');

function draw(time) {
  const dpr = devicePixelRatio || 1, { width: cw, height: ch } = canvas.getBoundingClientRect();
  canvas.width = cw * dpr; canvas.height = ch * dpr; ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  const m = { l: 44, r: 12, t: 16, b: 30 }, pw = cw - m.l - m.r, ph = ch - m.t - m.b;

  // axis labels and dotted guides
  ctx.font = '12px ui-monospace, monospace'; ctx.fillStyle = '#77736a'; ctx.strokeStyle = '#d8d3c8';
  ctx.textAlign = 'right'; ctx.textBaseline = 'middle';
  for (let v = 0; v <= max; v += max / 4) {
    const y = Math.round(m.t + ph - v / max * ph) + 0.5;
    ctx.fillText(v + 'h', m.l - 10, y);
    ctx.setLineDash(v ? [2, 4] : []); ctx.beginPath(); ctx.moveTo(m.l, y); ctx.lineTo(m.l + pw, y); ctx.stroke();
  }

  // the dots, drawn small and scaled up without smoothing so each one stays a crisp square
  const W = Math.floor(pw / settings.dot), H = Math.floor(ph / settings.dot);
  pix.width = W; pix.height = H;
  const img = pctx.createImageData(W, H), d = img.data, phase = time * settings.speed, n = settings.bands;
  for (let x = 0; x < W; x++) {
    const v = valueAt(x / (W - 1));
    for (let y = 0; y < H; y++) {
      const yv = (1 - (y + 0.5) / H) * max;
      if (yv > v) continue;                                                     // above the line: empty
      if (1 - (v - yv) / v * settings.fill <= B8[y & 7][x & 7]) continue;     // dense at the line, thinning toward the baseline
      // each dot's band is dithered against the next, so bands blend instead of stopping hard
      const f = (yv / max) * n * 1.6 - phase;
      let band = Math.floor(f);
      if (f - band > B8[(y + 3) & 7][(x + 5) & 7]) band++;
      const k = ((band % (2 * n)) + 2 * n) % (2 * n), c = rampAt((k < n ? k : 2 * n - 1 - k) / Math.max(1, n - 1));
      const i = (y * W + x) * 4; d[i] = c[0]; d[i + 1] = c[1]; d[i + 2] = c[2]; d[i + 3] = 255;
    }
  }
  pctx.putImageData(img, 0, 0);
  ctx.imageSmoothingEnabled = false;
  ctx.drawImage(pix, m.l, m.t, W * settings.dot, H * settings.dot);

  if (settings.note) {   // circle the peak and label it
    const peak = data.indexOf(Math.max(...data)), px = m.l + peak / (data.length - 1) * pw, py = m.t + ph - data[peak] / max * ph;
    ctx.strokeStyle = '#15130f'; ctx.lineWidth = 2; ctx.beginPath(); ctx.ellipse(px, py, 26, 20, 0, 0, Math.PI * 2); ctx.stroke();
    ctx.fillStyle = '#15130f'; ctx.textAlign = 'left'; ctx.font = 'italic 22px Georgia, serif'; ctx.fillText(settings.note, px + 36, py - 8);
  }
}

(function loop(now) { draw(now / 1000); requestAnimationFrame(loop); })(0);
</script>
```

-   [Previous piece — Ink Gain](https://reallygood.work/playground/ink-gain/)
-   [Next piece — Soft Grain](https://reallygood.work/playground/soft-grain/)
