Skip to content

3D bubble chart ​

Bubbles in a box with three axes, as large as a fourth value, shaded like balls, with their shadows on the floor. Good for four measures at once, 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: 'bubbles3d',
  titles: { x: 'Price', y: 'Reach', z: 'Margin' },
  series: [
    {
      name: 'North',
      data: [
        { x: 26, y: 26, z: 15, size: 50, label: 'North 1' },
        { x: 14, y: 15, z: 28, size: 56, label: 'North 2' },
        { x: 16, y: 19, z: 16, size: 24, label: 'North 3' },
        { x: 39, y: 11, z: 29, size: 5, label: 'North 4' },
        { x: 22, y: 19, z: 17, size: 74, label: 'North 5' },
        { x: 10, y: 27, z: 28, size: 47, label: 'North 6' },
        { x: 35, y: 17, z: 21, size: 55, label: 'North 7' },
      ],
    },
    {
      name: 'South',
      data: [
        { x: 58, y: 54, z: 39, size: 38, label: 'South 1' },
        { x: 34, y: 75, z: 30, size: 47, label: 'South 2' },
        { x: 61, y: 80, z: 32, size: 18, label: 'South 3' },
        { x: 54, y: 60, z: 36, size: 54, label: 'South 4' },
        { x: 42, y: 85, z: 32, size: 26, label: 'South 5' },
        { x: 39, y: 46, z: 30, size: 6, label: 'South 6' },
        { x: 43, y: 73, z: 39, size: 51, label: 'South 7' },
      ],
    },
    {
      name: 'East',
      data: [
        { x: 76, y: 14, z: 40, size: 59, label: 'East 1' },
        { x: 77, y: 37, z: 60, size: 42, label: 'East 2' },
        { x: 79, y: 34, z: 52, size: 83, label: 'East 3' },
        { x: 64, y: 23, z: 63, size: 34, label: 'East 4' },
        { x: 77, y: 36, z: 60, size: 18, label: 'East 5' },
        { x: 57, y: 45, z: 51, size: 97, label: 'East 6' },
        { x: 77, y: 16, z: 58, size: 53, label: 'East 7' },
      ],
    },
  ],
};

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

/** Bubbles in a box with three axes, as large as a fourth value, shaded like balls. */
interface Bubbles3DSpec extends Base3D {
  type: 'bubbles3d';
  /** `size` of each point is the fourth value: the area of its bubble follows it. */
  series: { name: string; color?: string; data: Point3D[] }[];
  /** Radius of the smallest and largest bubble, in pixels: [4, 24] by default. */
  radius?: [number, number];
  /** The shadow of each bubble on the floor: true by default. */
  shadows?: boolean;
  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