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):
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 |
bubbles3d | series: { name, data: { x, y, z, size }[] }[] | radius, shadows, titles |
area3d | categories, series | stacked, percent, thickness, min, max |
line3d | series: { name, data: { x, y, z, label? }[] }[] (points in their order) | markers, shadow, drops, titles |
histogram3d | z: number[][], x, y names | colors, width, titles |
heatmap3d | columns, rows, values: number[][] | colors, height |
waterfall3d | data: { name, value, total? }[] | up, down, totalColor, width, connectors |
gauge3d | value | min, max, bands: { to, color }[], target, name, unit, color |
cylinder3d | data: { name, value, max? }[] | max (size of the tanks), unit |
cone3d | data (first at the top) | sizing: 'volume' | 'height' | 'equal', apex: 'top' | 'bottom', gap |
polar3d | data | radius: 'value' | 'equal', height, labels, legend |
globe3d | data: { name, lon, lat, value }[] | geo (land), shape: 'bar' | 'spike', height, color |
building3d | data (the ground floor first; value may be null) | colors, min, max, footprint, windows |
treemap3d | data: { name, value, height? }[] | height, legend |
flow3d | links: { source, target, value }[] | colors by node |
radar3d | axes, series | max, legend |
progress3d | data: { name, value, target?, max? }[] | max |
pictorial3d | data | icon: 'cube' | 'house' | 'car' | 'tree' | 'cylinder', unit, perRow |
candles3d | data: { label, open, high, low, close, volume? }[] | up, down |
timeline3d | events: { label, date?, text? }[] | color (of the road) |
wall3d | data: { date: 'YYYY-MM-DD', value }[] | colors, weekStart |
A few notes on the newer types:
area3dfills each series down to the floor, as a solid layer behind the one before (the first series at the back);stacked: truepiles the series into one block,percent: truemakes every category 100 % high.ribbon3ddraws the same data as thinner ribbons.bubbles3disscatter3dwith a fourth value: the area of each ball follows itssize, and its shadow on the floor tells where it stands.line3djoins 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.histogram3dandheatmap3dtake 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.waterfall3dreadsdatalike the flatwaterfall: a step adds its value to the running total, atotalstands from the floor; the tooltips give the change and the running total.gauge3dis a dial lying on a table: tilt it withview.elevation(90 shows it flat, from above).cylinder3dfills a glass tank for each item; the tooltip gives the share of the tank and its size.cone3dcuts 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.polar3dgives 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
globe3dstands a bar (or a spike withshape: 'spike') on each place, as high as its value, on a globe seen from far away. Without aview, the eye faces the middle of the places; drag it, or use the arrow keys of the turn button, to turn the Earth.geodraws the land (theworldorcontinentsfile ofloadMap); 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.building3dcolours 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.treemap3dlays 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).flow3dis 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.radar3draises the polygon of each series as a plate, the first one at the bottom; the dots on the plates are read with the keyboard.progress3dfills a glass tube for each item up to its value, out of its ownmaxor the common one; a dark ring marks itstarget.pictorial3dcounts units with icons in one lane for each item:1 icon = 10is 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, unlessunitsays otherwise.candles3ddraws each candlestick as a box, as deep as its volume, with the prices on the back walls.timeline3dputs events on posts along a road that goes away from the eye, the first one in front; adateplaces them, else they are evenly spaced.wall3dis 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.