Multi-line
metrics over time
Metrics over time. Keep it under about five series, or switch to horizon.
- Format.d3
- Length81 lines
- Includesnone
The source
81 lines of D3 JavaScript, and uses only the bundled D3 build. Copy it, or open the template inside Gnomon and render it as it is.
// Multi-line time series with labels at the line ends rather than a
// legend — the reader never has to match a colour swatch to a line.
const rng = d3.randomLcg(17);
const names = ['orders', 'catalogue', 'payments', 'identity'];
const start = new Date(Date.UTC(2026, 0, 1));
const days = d3.utcDay.range(start, d3.utcDay.offset(start, 120));
const series = names.map((name, i) => ({
name,
values: days.map((date, t) => ({
date,
value: Math.max(1, 60 + i * 25 + 22 * Math.sin((t + i * 9) / 13) + rng() * 12 - 6),
})),
}));
const margin = { top: 48, right: 96, bottom: 40, left: 56 };
const x = d3.scaleUtc()
.domain(d3.extent(days))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain([0, d3.max(series, s => d3.max(s.values, v => v.value))]).nice()
.range([height - margin.bottom, margin.top]);
const color = d3.scaleOrdinal(names, theme.palette);
const line = d3.line()
.x(d => x(d.date))
.y(d => y(d.value))
.curve(d3.curveMonotoneX);
const svg = d3.select(container).append('svg')
.attr('viewBox', [0, 0, width, height])
.attr('width', width)
.attr('height', height)
.attr('font-family', 'system-ui, sans-serif')
.attr('font-size', 11);
svg.append('g')
.attr('transform', `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(6))
.call(g => g.select('.domain').remove())
.call(g => g.selectAll('text').attr('fill', theme.muted))
.call(g => g.selectAll('line')
.attr('stroke', theme.muted).attr('stroke-opacity', 0.22)
.attr('x2', width - margin.left - margin.right));
svg.append('g')
.attr('transform', `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(6))
.call(g => g.select('.domain').attr('stroke', theme.muted))
.call(g => g.selectAll('text').attr('fill', theme.muted))
.call(g => g.selectAll('line').attr('stroke', theme.muted));
svg.append('g')
.attr('fill', 'none')
.attr('stroke-width', 2)
.selectAll('path')
.data(series)
.join('path')
.attr('stroke', d => color(d.name))
.attr('d', d => line(d.values));
svg.append('g')
.selectAll('text')
.data(series)
.join('text')
.attr('x', width - margin.right + 8)
.attr('y', d => y(d.values[d.values.length - 1].value))
.attr('dy', '0.35em')
.attr('fill', d => color(d.name))
.attr('font-weight', 600)
.text(d => d.name);
svg.append('text')
.attr('x', margin.left)
.attr('y', 24)
.attr('fill', theme.foreground)
.attr('font-size', 13)
.attr('font-weight', 600)
.text('Requests per second by service');Render this offline
This template ships in Gnomon and renders on your machine, with no account and nothing sent to a server. The browser editor is free and needs no install.
Others in D3 visualisations
- Sankey — request flowFlow with volume. The best chart here for "where does it all go".
- Chord — service interactionWho talks to whom, when the traffic is bidirectional.
- Arc diagram — dependenciesNodes on one axis, arcs above. Readable where a force graph is not, provided the ordering means something.
- Adjacency matrix — couplingAdjacency matrix. Unfashionable, and better than a force graph for dense dependencies.
- Edge bundling — module importsHierarchical edge bundling. For import graphs big enough that straight edges become a hairball.
- Sunburst — nested spendNested hierarchy, radially. Prettier than an icicle, harder to compare.
- Icicle — nested spend (linear)A sunburst unrolled flat. Harder to love, much easier to compare siblings.
- Circle packing — nested sizeCircle packing. Nested size when the nesting matters more than reading exact areas.
- Treemap — portfolio costNested size. Good for cost, storage, lines of code.
- Tidy tree — structureA tidy tree. The default for anything with one parent per node.
- Radial tree — structure (radial)The same tree bent into a circle. Fits more depth on a slide, costs you easy comparison.
- Dendrogram — clusteringClustering, with join height carrying the distance. Not merely a tree with curves.
- Indented tree — file/spec outlineA file or spec outline. The chart that looks like the thing it describes.
- Force graph — service mapService map. Use for clusters, not for reading individual edges.
- Force graph — disjoint clustersForce graph that keeps unconnected clusters apart rather than flinging them off screen.
- Force graph — radial tiersForce layout pinned to rings, so tier is a position instead of a colour legend.
- Directed graph — call directionDirected edges with arrowheads. For when direction is the question, not just adjacency.
- Force tree — blast radiusBlast radius from one node: what breaks if this goes.
- Calendar heatmap — daily activityDaily activity over a year: deploys, incidents, commits.
- Streamgraph — shifting mixShifting composition over time. Good for the mix, poor for reading any single value.
- Gantt — delivery roadmapDelivery roadmap, rendered from data.
- Radar — capability scoringCapability scoring across axes. Fine for one subject, misleading with four overlaid.
- Bullet chart — target vs actualTarget against actual, in one line. The chart a gauge wishes it were.
- Beeswarm — distribution by groupEvery point, grouped, without the overplotting a strip plot suffers.
- Horizon chart — many series, little spaceMany series in little space. Takes a moment to learn, then very dense.
- Slope chart — before and afterBefore and after, two points, one line each. Devastatingly clear.
- Parallel coordinates — multi-criteriaMulti-criteria comparison: for option analysis.
- Box plot — latency distributionLatency distribution. The chart that shows the tail a mean hides.
- Grouped bar — category comparisonCategory comparison. Unglamorous, and usually the right answer.