Skip to content

3D surface ​

A grid of heights drawn as a surface, coloured by height, that turns when dragged. Good for a value that depends on two others: terrain, a response surface, a yield by price and volume.

The smallest code that works. change the code, then press Run

In your framework

import { Chart } from 'nervure/react';
import 'nervure/3d';

const spec = {
  type: 'surface3d',
  x: [
    '0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55', '60', '65', '70',
    '75', '80', '85', '90', '95', '100',
  ],
  y: [
    '0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55', '60', '65', '70',
    '75', '80', '85', '90', '95', '100',
  ],
  z: [
    [
      2.2, 0.8, -0.6, -1.9, -3, -3.7, -3.9, -3.5, -2.6, -1.1, 0.7, 2.7, 4.6, 6.3, 7.5, 8.2, 8.6,
      8.6, 8.4, 8, 7.5,
    ],
    [
      2.1, 0.8, -0.5, -1.6, -2.5, -2.9, -2.7, -1.9, -0.4, 1.7, 4.2, 6.7, 8.9, 10.6, 11.6, 11.9,
      11.6, 10.8, 9.9, 8.9, 7.9,
    ],
    [
      1.7, 0.7, -0.3, -1.1, -1.5, -1.5, -0.8, 0.7, 3, 5.8, 9, 12, 14.6, 16.2, 16.8, 16.3, 15,
      13.3, 11.4, 9.6, 8,
    ],
    [
      1.2, 0.6, 0, -0.3, -0.2, 0.4, 1.8, 4.1, 7.1, 10.8, 14.8, 18.4, 21.2, 22.7, 22.7, 21.3,
      18.8, 15.8, 12.8, 10, 7.7,
    ],
    [
      0.6, 0.4, 0.4, 0.7, 1.3, 2.7, 4.8, 7.8, 11.7, 16.3, 20.9, 25.1, 28.1, 29.3, 28.7, 26.2,
      22.5, 18.2, 13.9, 10.1, 7,
    ],
    [
      -0.1, 0.3, 0.8, 1.7, 3, 5, 7.8, 11.5, 16.2, 21.4, 26.7, 31.2, 34.3, 35.2, 33.9, 30.5, 25.6,
      20, 14.6, 9.8, 6.1,
    ],
    [
      -0.7, 0.2, 1.3, 2.8, 4.7, 7.2, 10.6, 14.9, 20, 25.6, 31.2, 35.9, 38.8, 39.4, 37.5, 33.3,
      27.4, 20.9, 14.6, 9.1, 4.9,
    ],
    [
      -1.1, 0.3, 1.9, 3.9, 6.3, 9.3, 13, 17.5, 22.8, 28.4, 33.9, 38.4, 41, 41.3, 38.8, 34, 27.6,
      20.6, 13.8, 8, 3.6,
    ],
    [
      -1.3, 0.5, 2.7, 5.2, 8, 11.3, 15.1, 19.5, 24.5, 29.6, 34.6, 38.5, 40.6, 40.4, 37.6, 32.7,
      26.2, 19.1, 12.3, 6.5, 2.2,
    ],
    [
      -1.1, 1.1, 3.7, 6.7, 9.9, 13.4, 17.1, 21, 25.2, 29.5, 33.3, 36.3, 37.7, 37.1, 34.2, 29.4,
      23.2, 16.5, 10.2, 4.9, 0.9,
    ],
    [
      -0.5, 2.1, 5.2, 8.6, 12.1, 15.7, 19.1, 22.3, 25.4, 28.3, 30.8, 32.6, 33.1, 32, 29.2, 24.8,
      19.3, 13.5, 8, 3.4, 0,
    ],
    [
      0.6, 3.5, 6.9, 10.8, 14.7, 18.3, 21.3, 23.6, 25.4, 26.7, 27.5, 27.9, 27.5, 26.1, 23.4,
      19.6, 15.1, 10.4, 6, 2.3, -0.5,
    ],
    [
      1.9, 5, 8.8, 13.1, 17.2, 20.8, 23.4, 24.8, 25.2, 24.8, 24.1, 23.2, 21.9, 20.2, 17.8, 14.7,
      11.3, 7.7, 4.4, 1.7, -0.4,
    ],
    [
      3.4, 6.5, 10.6, 15, 19.4, 22.9, 25.1, 25.6, 24.7, 22.9, 20.7, 18.7, 16.7, 14.8, 12.8, 10.6,
      8.2, 5.8, 3.5, 1.7, 0.3,
    ],
    [
      4.6, 7.7, 11.7, 16.2, 20.5, 23.8, 25.5, 25.3, 23.4, 20.5, 17.4, 14.6, 12.3, 10.4, 8.9, 7.4,
      6, 4.6, 3.3, 2.3, 1.4,
    ],
    [
      5.6, 8.3, 11.9, 16.1, 20.1, 23, 24.2, 23.5, 21, 17.6, 14, 10.9, 8.5, 6.9, 5.9, 5.2, 4.7,
      4.1, 3.7, 3.2, 2.8,
    ],
    [
      6, 8.1, 11.1, 14.6, 18, 20.3, 21.1, 20.1, 17.5, 14, 10.5, 7.5, 5.5, 4.3, 3.9, 3.8, 3.9,
      4.1, 4.2, 4.3, 4.1,
    ],
    [
      5.9, 7.3, 9.5, 12, 14.5, 16.2, 16.6, 15.4, 13, 9.9, 6.9, 4.5, 3, 2.4, 2.5, 2.9, 3.6, 4.3,
      4.8, 5.2, 5.3,
    ],
    [
      5.3, 6, 7.3, 8.9, 10.5, 11.5, 11.5, 10.4, 8.4, 5.9, 3.6, 1.9, 1.1, 1, 1.5, 2.4, 3.4, 4.4,
      5.2, 5.7, 5.9,
    ],
    [
      4.5, 4.6, 5.1, 5.8, 6.6, 7, 6.7, 5.8, 4.2, 2.5, 1, 0, -0.3, 0.1, 0.9, 2, 3.2, 4.3, 5.2,
      5.8, 6,
    ],
    [
      3.6, 3.2, 3.2, 3.3, 3.5, 3.5, 3.1, 2.3, 1.3, 0.2, -0.7, -1.1, -1, -0.4, 0.5, 1.6, 2.8, 3.8,
      4.7, 5.2, 5.5,
    ],
  ],
  titles: { x: 'East (km)', y: 'North (km)', z: 'Height (m)' },
};

export default function Example() {
  return <Chart spec={spec} style={{ height: 340 }} />;
}

Or import this chart alone: what each import weighs.

Options

Beside the fields shared by every chart (title, format, heading, export…), type surface3d takes:

/** A surface over a grid: `z[row][column]`, coloured by height. */
interface Surface3DSpec extends Base3D {
  type: 'surface3d';
  /** Heights, one row for each `y`, one value for each `x`; null leaves a hole. */
  z: (number | null)[][];
  /** Names of the columns of `z`, along the width. */
  x?: string[];
  /** Names of the rows of `z`, along the depth. */
  y?: string[];
  /** Colours from the lowest to the highest value. */
  colors?: string[];
  /** Lines only, without filled faces. */
  wireframe?: boolean;
  /** Names of the three axes. */
  titles?: { x?: string; y?: string; z?: string };
}

interface Base3D extends Base {
  /** Where the eye stands, in degrees: `azimuth` turns around the vertical axis, `elevation` rises from the floor (0) to straight above (90). */
  view?: { azimuth?: number; elevation?: number };
  /** Drag the chart, or focus its turn button and use the arrow keys, to turn the view. Home on the button goes back to `view`. */
  rotate?: boolean;
}

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it