Door-to-door journeys
Several ways of making one trip, their legs to scale, with the time, cost and CO₂ of each. Good for comparing the metro, the bus, the bike and the car for the same trip.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
import 'nervure/themes';
const spec = {
type: 'journeys',
format: { currency: 'EUR' },
data: [
{
name: 'Metro',
mode: 'metro',
cost: 2.15,
co2: 0.1,
legs: [
{ kind: 'walk', minutes: 6 },
{ kind: 'wait', minutes: 3 },
{ kind: 'ride', minutes: 15, name: 'Line 4' },
{ kind: 'walk', minutes: 4 },
],
},
{
name: 'Bus',
mode: 'bus',
cost: 2.15,
co2: 0.6,
legs: [
{ kind: 'walk', minutes: 2 },
{ kind: 'wait', minutes: 6 },
{ kind: 'ride', minutes: 30, name: 'Bus 38' },
{ kind: 'walk', minutes: 4 },
],
},
{ name: 'Bike', mode: 'bike', cost: 0, co2: 0, legs: [{ kind: 'bike', minutes: 24 }] },
{
name: 'Car',
mode: 'car',
cost: 7,
co2: 3.8,
legs: [
{ kind: 'walk', minutes: 1 },
{ kind: 'drive', minutes: 21, name: 'Ring road' },
{ kind: 'park', minutes: 6 },
{ kind: 'walk', minutes: 6 },
],
},
],
};
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 journeys takes:
/** Door to door, several ways of making the same trip: their legs to scale, the time, cost and CO₂ of each. */
interface JourneysSpec extends Base {
type: 'journeys';
data: { name: string; mode?: TravelMode; legs: JourneyLeg[]; cost?: number; co2?: number; color?: string }[];
onItemClick?: (name: string) => void;
}
/** A way of moving, drawn with its own icon. */
type TravelMode = 'walk' | 'bike' | 'scooter' | 'bus' | 'tram' | 'metro' | 'train' | 'car' | 'carpool' | 'plane';
/** One leg of a trip: on foot, waiting, on board, at the wheel. */
interface JourneyLeg {
kind: 'walk' | 'wait' | 'ride' | 'drive' | 'bike' | 'park';Style it
- Colours:
theme.palette,chart.setColor(name, colour), or--nervure-palettein your CSS. More - Marks:
[data-series="name"], parts:[data-part="axes"],legend,series. What you change is kept in exports. - Movement:
animation: falsedraws at once. More - Files:
chart.download('png'),svg,csv. More