Skip to content

3D scatter plot ​

Points in a box with three axes, sized by a fourth value, with lines down to the floor. Good for clusters on three measures, explored by turning the box.

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: 'scatter3d',
  drops: true,
  titles: { x: 'Price', y: 'Weight', z: 'Score' },
  series: [
    {
      name: 'North',
      data: [
        { x: 26, y: 26, z: 17, size: 10 },
        { x: 14, y: 11, z: 34, size: 11 },
        { x: 16, y: 18, z: 18, size: 5 },
        { x: 39, y: 6, z: 35, size: 1 },
        { x: 22, y: 18, z: 20, size: 15 },
        { x: 10, y: 28, z: 33, size: 9 },
        { x: 35, y: 15, z: 25, size: 11 },
        { x: 36, y: 17, z: 32, size: 8 },
        { x: 12, y: 46, z: 21, size: 9 },
        { x: 39, y: 52, z: 24, size: 4 },
        { x: 32, y: 26, z: 29, size: 11 },
        { x: 20, y: 60, z: 24, size: 5 },
        { x: 17, y: 6, z: 21, size: 1 },
        { x: 21, y: 44, z: 33, size: 10 },
      ],
    },
    {
      name: 'South',
      data: [
        { x: 57, y: 40, z: 33, size: 12 },
        { x: 58, y: 72, z: 59, size: 8 },
        { x: 60, y: 68, z: 49, size: 17 },
        { x: 45, y: 53, z: 64, size: 7 },
        { x: 58, y: 71, z: 60, size: 4 },
        { x: 38, y: 82, z: 48, size: 19 },
        { x: 58, y: 43, z: 57, size: 11 },
        { x: 43, y: 73, z: 43, size: 6 },
        { x: 63, y: 57, z: 26, size: 6 },
        { x: 63, y: 78, z: 42, size: 16 },
        { x: 50, y: 39, z: 28, size: 13 },
        { x: 50, y: 63, z: 49, size: 7 },
        { x: 51, y: 65, z: 54, size: 19 },
        { x: 45, y: 65, z: 31, size: 5 },
      ],
    },
    {
      name: 'East',
      data: [
        { x: 81, y: 43, z: 51, size: 2 },
        { x: 78, y: 42, z: 65, size: 15 },
        { x: 84, y: 8, z: 75, size: 11 },
        { x: 67, y: 14, z: 80, size: 18 },
        { x: 81, y: 14, z: 63, size: 19 },
        { x: 64, y: 40, z: 69, size: 12 },
        { x: 89, y: 21, z: 55, size: 19 },
        { x: 88, y: 18, z: 69, size: 8 },
        { x: 90, y: 13, z: 47, size: 2 },
        { x: 83, y: 38, z: 78, size: 10 },
        { x: 84, y: 54, z: 48, size: 12 },
        { x: 88, y: 22, z: 53, size: 20 },
        { x: 83, y: 46, z: 69, size: 13 },
        { x: 62, y: 14, z: 72, size: 14 },
      ],
    },
  ],
};

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 scatter3d takes:

/** Points in a box with three axes. */
interface Scatter3DSpec extends Base3D {
  type: 'scatter3d';
  series: { name: string; color?: string; data: Point3D[] }[];
  /** A thin line from each point down to the floor, with its shadow. */
  drops?: boolean;
  /** Radius of the smallest and largest point, in pixels, when they have a `size`: [3, 14] by default. */
  radius?: [number, number];
  titles?: { x?: string; y?: string; z?: string };
  legend?: boolean | LegendOptions;
}

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