Skip to content

3D charts ​

Thirty chart types draw solids with a thickness: pie3d, donut3d, columns3d, stacked3d, ribbon3d, area3d, surface3d, scatter3d, bubbles3d, line3d, histogram3d, heatmap3d, waterfall3d, gauge3d, cylinder3d, pyramid3d, funnel3d, cone3d, polar3d, map3d, globe3d, building3d, treemap3d, flow3d, radar3d, progress3d, pictorial3d, candles3d, timeline3d and wall3d. They are plain SVG (no WebGL, no canvas), so they export to SVG and PNG, take the theme and the palette, have tooltips, a legend and keyboard reading like every other chart. bars3d is the older isometric chart of the main file.

Load them ​

The 3D types are a separate entry, so they do not grow the main file (about 35 kB gzipped for all thirty):

ts
import { createChart } from 'nervure';
import 'nervure/3d'; // registers the 3D types

createChart(host, { type: 'pie3d', data: [{ name: 'Rent', value: 42 }, { name: 'Food', value: 30 }] });

In a page without a bundler, load the browser file after the main one:

html
<script src="https://cdn.jsdelivr.net/npm/nervure"></script>
<script src="https://cdn.jsdelivr.net/npm/nervure/cdn/nervure.3d.min.js"></script>

nervure/lazy knows them too: createChart from nervure/lazy fetches the code of a 3D type the first time it is drawn.

The view and turning it ​

Every 3D chart takes a view, in degrees: azimuth turns around the vertical axis, elevation goes from the floor (0) to straight above (90). Each type has a default that shows it well.

ts
{ type: 'surface3d', z, view: { azimuth: 60, elevation: 35 }, rotate: true }

With rotate: true:

  • a drag on the chart turns it (left and right around, up and down in height);
  • a button in the top right corner takes the focus with Tab; the arrow keys turn the view by steps, Enter or Home goes back to view.

Each step draws the chart again from the new eye, so the labels, the tooltips and the order in which the faces cover one another stay right; nothing is a CSS transform. Turning keeps the size of the drawing, so nothing jumps. chart.update(spec) goes back to the view of the spec.

The faces take the colour of their series in the light: tops lighter, sides darker. This works in the light and dark themes and with your palette (colours written as #rgb, #rrggbb or rgb(); other colours are drawn flat). With reduced motion, the charts appear at once, as every other chart does.

The types ​

TypeDataOptions
pie3d, donut3ddata: { name, value }[]explode (names or indexes), depth, hole (donut), labels, legend
columns3dcategories, series: { name, data }[]shape: 'box' | 'cylinder' | 'cone' | 'pyramid', width, min, max
stacked3dcategories, seriespercent, shape: 'box' | 'cylinder'
ribbon3dcategories, seriesthickness, curve: 'smooth'
surface3dz: number[][], x, y namescolors, wireframe, titles
scatter3dseries: { name, data: { x, y, z, size? }[] }[]drops, radius, titles
pyramid3ddata (first at the top)sizing: 'value' | 'equal', shape: 'square' | 'round', gap
funnel3ddata (first at the top)shape, gap
map3dgeo (GeoJSON or TopoJSON), values by idkey, nameKey, color, height
bubbles3dseries: { name, data: { x, y, z, size }[] }[]radius, shadows, titles
area3dcategories, seriesstacked, percent, thickness, min, max
line3dseries: { name, data: { x, y, z, label? }[] }[] (points in their order)markers, shadow, drops, titles
histogram3dz: number[][], x, y namescolors, width, titles
heatmap3dcolumns, rows, values: number[][]colors, height
waterfall3ddata: { name, value, total? }[]up, down, totalColor, width, connectors
gauge3dvaluemin, max, bands: { to, color }[], target, name, unit, color
cylinder3ddata: { name, value, max? }[]max (size of the tanks), unit
cone3ddata (first at the top)sizing: 'volume' | 'height' | 'equal', apex: 'top' | 'bottom', gap
polar3ddataradius: 'value' | 'equal', height, labels, legend
globe3ddata: { name, lon, lat, value }[]geo (land), shape: 'bar' | 'spike', height, color
building3ddata (the ground floor first; value may be null)colors, min, max, footprint, windows
treemap3ddata: { name, value, height? }[]height, legend
flow3dlinks: { source, target, value }[]colors by node
radar3daxes, seriesmax, legend
progress3ddata: { name, value, target?, max? }[]max
pictorial3ddataicon: 'cube' | 'house' | 'car' | 'tree' | 'cylinder', unit, perRow
candles3ddata: { label, open, high, low, close, volume? }[]up, down
timeline3devents: { label, date?, text? }[]color (of the road)
wall3ddata: { date: 'YYYY-MM-DD', value }[]colors, weekStart

A few notes on the newer types:

  • area3d fills each series down to the floor, as a solid layer behind the one before (the first series at the back); stacked: true piles the series into one block, percent: true makes every category 100 % high. ribbon3d draws the same data as thinner ribbons.
  • bubbles3d is scatter3d with a fourth value: the area of each ball follows its size, and its shadow on the floor tells where it stands.
  • line3d joins the points of each series in their order, a path through space, and draws it again on the floor; the pieces of the path and the balls are sorted by depth, so a path that crosses itself is drawn right.
  • histogram3d and heatmap3d take a grid of values: the first is a city of columns with an axis of heights, the second a flat grid of tiles with a colour scale, for when the colour matters more than the height.
  • waterfall3d reads data like the flat waterfall: a step adds its value to the running total, a total stands from the floor; the tooltips give the change and the running total.
  • gauge3d is a dial lying on a table: tilt it with view.elevation (90 shows it flat, from above).
  • cylinder3d fills a glass tank for each item; the tooltip gives the share of the tank and its size.
  • cone3d cuts a cone into slices; by default each slice holds a share of its volume as large as its value, so the slices near the point are taller.
  • polar3d gives each item a wedge of the same angle, as high as its value and with an area that follows it (radius: 'equal' keeps them all as wide).

Every field is on the page of each chart in the gallery.

Globes, buildings and other pictures ​

  • globe3d stands a bar (or a spike with shape: 'spike') on each place, as high as its value, on a globe seen from far away. Without a view, the eye faces the middle of the places; drag it, or use the arrow keys of the turn button, to turn the Earth. geo draws the land (the world or continents file of loadMap); without it the globe has a grid of meridians and parallels only. Bars behind the Earth stay hidden, except where they stand out of its rim.

  • building3d colours each floor of a building by its value — occupancy, energy, rent — with windows on its walls and the names of the floors on the right. The first item is the ground floor.

  • treemap3d lays the tiles of a treemap on a floor and raises them, by their value or by a second value, height (the growth of a shop, its margin).

  • flow3d is a Sankey diagram lying on a table: a block for each node, the stages from left to right, the flows as thick ribbons as wide as their value.

  • radar3d raises the polygon of each series as a plate, the first one at the bottom; the dots on the plates are read with the keyboard.

  • progress3d fills a glass tube for each item up to its value, out of its own max or the common one; a dark ring marks its target.

  • pictorial3d counts units with icons in one lane for each item: 1 icon = 10 is written in the corner, and the last icon is cut to the share left over. The unit is chosen so that the longest lane holds at most 40 icons, unless unit says otherwise.

  • candles3d draws each candlestick as a box, as deep as its volume, with the prices on the back walls.

  • timeline3d puts events on posts along a road that goes away from the eye, the first one in front; a date places them, else they are evenly spaced.

  • wall3d is a calendar heatmap built as a wall of blocks, one for each day, weeks along the width and days of the week across.

When 3D is a bad idea ​

Most of the time. A 3D chart is harder to read than the flat one it comes from:

  • Lengths and angles lie. A slice at the front of a 3D pie looks larger than the same slice at the back; a column far away seems shorter. Readers compare shapes, not numbers.
  • Things hide each other. A tall column, ribbon or region covers what stands behind it. Turning helps, but a printed page or a screenshot cannot turn.
  • The axes are hard to follow. Reading a height against a grid on the back wall is slow and inaccurate.

So prefer the flat charts — xy bars, pie, heatmap, scatter, map — to report figures, and keep 3D for a cover, a slide or a picture meant to strike, with few categories and the figures in the tooltips or in a table (table: 'toggle'). Two cases where 3D earns its place: a surface of a value that depends on two others, which a flat heatmap shows less naturally, and a 3D scatter explored by turning it, to see clusters on three measures.

The keyboard, the screen reader text and the CSV, Markdown and table exports carry the exact figures whatever the picture shows.

Size ​

The charts stay readable at 300 px wide; below 150 px the axes and labels give way, and below 110 px high the legend too, and only the drawing is kept.