Skip to content

Chart types reference ​

How to build each chart type. They are all the same kind of thing: axes, one or several renderers, sometimes a transform that derives a series, sometimes annotations. The gallery shows each of them, with its source.

Chart typeHow
Line, area, scatterD3PLineRenderer, D3PAreaRenderer, D3PScatterRenderer
Spline, stepstyle.curve: monotone, step, stepBefore, stepAfter, basis, cardinal, catmullRom, natural
Gaps in the datastyle.gaps: 'break' (default connect)
ColumnsD3PBarRenderer on a band axis; count and index group several series side by side
Horizontal barsD3PBarRenderer with orientation: 'horizontal', categories on a band axis at the left
Stacked, 100 %, streamgraphD3PStack with offset: 'none' | 'expand' | 'silhouette' | 'wiggle' (and order), drawn by areas or bars
Range areaa series with columns: ['x', 'high', 'low'] and D3PAreaRenderer({ props: { base: 'low' } })
Range column, timelineD3PBarRenderer with base: 'start' (and orientation: 'horizontal' for a timeline)
HistogramD3PHistogram (or d3pHistogram) feeding D3PBarRenderer: bars take their width from the bin edges
WaterfallD3PWaterfall feeding D3PBarRenderer with style.colorBy: 'kind'
LollipopD3PBarRenderer with style.shape: 'lollipop'
CandlestickD3PCandlestickRenderer on a series with open, high, low, close
Box plotD3PBoxPlotRenderer; d3pBoxPlotRows(groups) computes quartiles, whiskers and outliers from raw samples
DumbbellD3PDumbbellRenderer on a series with start and end
BubbleD3PBubbleRenderer on a series with a size column
HeatmapD3PHeatmapRenderer with a D3PColorScale, and a D3PColorLegend
Pie, donut, semi-donutD3PPieRenderer in a D3PPolarSystem (innerRadius, sweep)
Radarpolar axes with D3PRadarAngleAxisRenderer, and lines or areas with curve: 'straight' and closed: true
Polar area (rose)D3PBarRenderer on polar axes, categories on the angle
Radial bar, gaugeD3PBarRenderer with orientation: 'horizontal' on polar axes, categories on the radius; sweep: 180 for a gauge
FunnelD3PFunnelRenderer (no axes)
Slopelines on a point axis with a blank category at each end
Sparklined3pSparkline({ container, data, type })
AnnotationsD3PAnnotationLine, D3PAnnotationBand, D3PAnnotationPoint, D3PAnnotationText

Not included: treemap, sunburst and icicle (they need hierarchical data), violin and raincloud, waffle, unit and beeswarm, and the multi-chart features (trellis, crossfilter, linked selections).

Data ​

A series is a list of points; a point is [x, value, ...others]. The columns have names, and a renderer asks for the ones it needs:

ts
// two columns, as always
new D3PSeries({ name: 'cpu', data: [[0, 3], [1, 5]] })

// several columns: a candlestick needs open, high, low and close
new D3PSeries({
  name: 'AAPL',
  columns: ['x', 'open', 'high', 'low', 'close'],
  primary: 'close',          // what a single value means (tooltip marker, legend, default domain)
  data: rows,
})

primary defaults to the second column. A renderer that needs columns the series lacks refuses it when attached, and says which ones.

Accepted inputs, detected on the first row:

InputExample
numbers, typed arrays[3, 5, 2]: x is the index (two columns only)
positional rows[[0, 3], ['a', 5]], in the order of columns
object rows[{ x: 0, y: 3 }], or other keys and functions with fields: { x: 't', y: (row) => row.v }
column-oriented{ x: [0, 1], y: [3, 5] }
any iterable of thosea Set, a generator, Map.entries()

Fitting the domains ​

D3PAutoDomain.linkSeries(series, [dx, dy]) fits the second domain to every value column (a candlestick's lows and highs, not only its close). Columns that are not positions (size, value, kind, color, label) are left out; domainColumns overrides this. To map columns one by one, use names: linkSeries(series, { x: dx, value: colors.domain }).

Derived series ​

A transform derives series from other series and keeps them up to date. The derived series are ordinary series that carry extra columns for the renderers:

TransformDerived columns
D3PStackx, y (top of the layer), y0 (its base), value (the original value, which the tooltip shows)
D3PWaterfallx, y, y0, value, kind (up, down, total)
D3PHistogramx, y (count), x0, x1 (the edges of the bin)

Areas and bars read a y0 column by themselves, or the one named by base.

Coordinate systems ​

Bars, areas, lines, scatter, bubbles and heatmaps draw in any coordinate system: rectangles in a cartesian one, arcs in a polar one, so the same renderer gives a column chart or a polar area. Candlesticks, box plots and dumbbells draw rectangles and lines and are cartesian only; pies are polar only; funnels use no system. A renderer that does not support a system says so.

A polar system can cover part of a circle (sweep), be a ring (innerRadius), start anywhere (startAngle) and be moved (shift, as fractions of the radius, to center a half disc).