Train crowding
The cars of a train along its platform, by how full they are, and where to wait. Good for station screens and travel apps.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'train',
sectors: ['A', 'B', 'C', 'D', 'E', 'F'],
cars: [
{ name: '1', load: 0.38, tags: ['first'] },
{ name: '2', load: 0.34, tags: ['quiet'] },
{ name: '3', load: 0.47, tags: [] },
{ name: '4', load: 0.69, tags: ['accessible'] },
{ name: '5', load: 0.43, tags: [] },
{ name: '6', load: 0.43, tags: [] },
{ name: '7', load: 0.78, tags: [] },
{ name: '8', load: 0.72, tags: ['bike'] },
],
};
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 train takes:
/** A train along its platform: how full each car is, and where to wait. */
interface TrainSpec extends Base {
type: 'train';
/** From the front of the train. `load` from 0 to 1. */
cars: { name?: string; load: number; tags?: ('first' | 'bike' | 'accessible' | 'quiet')[] }[];
/** Platform sectors, written under the train: A, B, C… */
sectors?: string[];
/** Where the train goes: left by default. */
direction?: 'left' | 'right';
onItemClick?: (name: string) => void;
}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