Skip to content

Transit map ​

Lines through their stations on a clean grid, with the interchanges where they meet. Good for metro, tram and bus networks, and any map of lines and stops.

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

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'metro',
  stations: [
    { id: 'bardo', name: 'Bardo', x: 0, y: 4, value: 33000 },
    { id: 'saadoun', name: 'Bab Saadoun', x: 2, y: 4, value: 26000 },
    { id: 'republique', name: 'République', x: 4, y: 4, side: 'bottom', value: 13000 },
    { id: 'barcelone', name: 'Barcelone', x: 6, y: 4, side: 'top', value: 31000 },
    { id: 'marine', name: 'Tunis Marine', x: 8.5, y: 4, value: 11000 },
    { id: 'goulette', name: 'La Goulette', x: 11, y: 4, side: 'right', value: 10000 },
    { id: 'ariana', name: 'Ariana', x: 4, y: 0, side: 'left', value: 38000 },
    { id: 'manar', name: 'El Manar', x: 4, y: 2, side: 'left', value: 34000 },
    { id: 'montfleury', name: 'Montfleury', x: 4, y: 6, side: 'left', value: 16000 },
    { id: 'benarous', name: 'Ben Arous', x: 6, y: 8, side: 'bottom', value: 17000 },
    { id: 'jelloud', name: 'Jebel Jelloud', x: 6, y: 6, side: 'right', value: 15000 },
    { id: 'marsa', name: 'La Marsa', x: 11, y: 0, side: 'right', value: 15000 },
    { id: 'carthage', name: 'Carthage', x: 11, y: 2, side: 'right', value: 57000 },
    { id: 'rades', name: 'Radès', x: 11, y: 6, side: 'right', value: 5000 },
    { id: 'ezzahra', name: 'Ezzahra', x: 11, y: 8, side: 'right', value: 39000, closed: true },
  ],
  lines: [
    { name: 'Line 1', stations: ['bardo', 'saadoun', 'republique', 'barcelone', 'marine', 'goulette'] },
    { name: 'Line 2', stations: ['ariana', 'manar', 'republique', 'montfleury', 'benarous'] },
    { name: 'Line 3', stations: ['marsa', 'carthage', 'goulette', 'rades', 'ezzahra'] },
    { name: 'Line 4', stations: ['barcelone', 'jelloud', 'benarous'] },
  ],
};

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

/** Schematic transit map: lines through their stations, interchanges where they meet. */
interface MetroSpec extends Base {
  type: 'metro';
  stations: MetroStation[];
  lines: MetroLine[];
  onItemClick?: (id: string) => void;
}

/** A station of a transit map, placed on a grid of your own units. */
interface MetroStation {
  id: string;

interface MetroLine {
  name: string;

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