Sleep stages
The stages of a night as steps, with the time spent in each. Good for sleep trackers and health reports.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'hypnogram',
start: '23:30',
data: [
{ stage: 'light', minutes: 13 },
{ stage: 'deep', minutes: 32 },
{ stage: 'light', minutes: 17 },
{ stage: 'rem', minutes: 9 },
{ stage: 'awake', minutes: 6 },
{ stage: 'light', minutes: 15 },
{ stage: 'deep', minutes: 24 },
{ stage: 'light', minutes: 13 },
{ stage: 'rem', minutes: 15 },
{ stage: 'awake', minutes: 8 },
{ stage: 'light', minutes: 8 },
{ stage: 'deep', minutes: 21 },
{ stage: 'light', minutes: 10 },
{ stage: 'rem', minutes: 22 },
{ stage: 'awake', minutes: 3 },
{ stage: 'light', minutes: 18 },
{ stage: 'deep', minutes: 4 },
{ stage: 'light', minutes: 16 },
{ stage: 'rem', minutes: 30 },
{ stage: 'light', minutes: 20 },
{ stage: 'deep', minutes: 4 },
{ stage: 'light', minutes: 16 },
{ stage: 'rem', minutes: 35 },
],
};
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 hypnogram takes:
/** The stages of a night of sleep. */
interface HypnogramSpec extends Base {
type: 'hypnogram';
/** In order; each stage lasts `minutes`. */
data: { stage: SleepStage; minutes: number }[];
/** Time of the first stage, "23:10". */
start?: string;
/** Name of each stage in another language. */
labels?: Partial<Record<SleepStage, string>>;
}
type SleepStage = 'awake' | 'rem' | 'light' | 'deep';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