Skip to content

3D line chart ​

A path through a box with three axes, with balls at its points and its shadow on the floor. Good for a trajectory: a flight, a walk, a value that moves on three measures.

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: 'line3d',
  titles: { x: 'East (m)', y: 'North (m)', z: 'Height (m)' },
  series: [
    {
      name: 'Flight',
      data: [
        { x: 48.8, y: 90, z: 7, label: '09:00' },
        { x: 36.6, y: 87.7, z: 10, label: '09:30' },
        { x: 25.7, y: 81.7, z: 15, label: '10:00' },
        { x: 17.1, y: 72.7, z: 17, label: '10:30' },
        { x: 11.7, y: 61.5, z: 21, label: '11:00' },
        { x: 10, y: 49.2, z: 27, label: '11:30' },
        { x: 12.2, y: 36.9, z: 31, label: '12:00' },
        { x: 18.1, y: 25.9, z: 34, label: '12:30' },
        { x: 27, y: 17.3, z: 38, label: '13:00' },
        { x: 38.2, y: 11.8, z: 42, label: '13:30' },
        { x: 50.5, y: 10, z: 46, label: '14:00' },
        { x: 62.8, y: 12.1, z: 53, label: '14:30' },
        { x: 73.8, y: 17.9, z: 53, label: '15:00' },
        { x: 82.5, y: 26.7, z: 59, label: '15:30' },
        { x: 88.1, y: 37.9, z: 61, label: '16:00' },
        { x: 90, y: 50.2, z: 67, label: '16:30' },
        { x: 88, y: 62.5, z: 70, label: '17:00' },
        { x: 82.3, y: 73.5, z: 74, label: '17:30' },
        { x: 73.5, y: 82.3, z: 80, label: '18:00' },
        { x: 62.4, y: 88, z: 81, label: '18:30' },
        { x: 50.2, y: 90, z: 87, label: '19:00' },
        { x: 37.9, y: 88.1, z: 91, label: '19:30' },
        { x: 26.7, y: 82.5, z: 95, label: '20:00' },
        { x: 17.9, y: 73.8, z: 100, label: '20:30' },
      ],
    },
  ],
};

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

/** A path through a box with three axes, with its shadow on the floor. */
interface Line3DSpec extends Base3D {
  type: 'line3d';
  /** The points of each path, in their order. */
  series: { name: string; color?: string; data: Point3D[] }[];
  /** A ball at each point: true by default. */
  markers?: boolean;
  /** The path drawn again on the floor: true by default. */
  shadow?: boolean;
  /** A thin line from each point down to the floor. */
  drops?: 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