3D charts
Ten chart types draw solids with a thickness: pie3d, donut3d, columns3d, stacked3d, ribbon3d, surface3d, scatter3d, pyramid3d, funnel3d and map3d. 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 14 kB gzipped for all ten):
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:
<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.
{ 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
| Type | Data | Options |
|---|---|---|
pie3d, donut3d | data: { name, value }[] | explode (names or indexes), depth, hole (donut), labels, legend |
columns3d | categories, series: { name, data }[] | shape: 'box' | 'cylinder' | 'cone' | 'pyramid', width, min, max |
stacked3d | categories, series | percent, shape: 'box' | 'cylinder' |
ribbon3d | categories, series | thickness, curve: 'smooth' |
surface3d | z: number[][], x, y names | colors, wireframe, titles |
scatter3d | series: { name, data: { x, y, z, size? }[] }[] | drops, radius, titles |
pyramid3d | data (first at the top) | sizing: 'value' | 'equal', shape: 'square' | 'round', gap |
funnel3d | data (first at the top) | shape, gap |
map3d | geo (GeoJSON or TopoJSON), values by id | key, nameKey, color, height |
Every field is on the page of each chart in the gallery.
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.