Skip to content

How-to

Make a themed chart

Charts are drawn on a plane and coloured from the theme, so you rarely choose a colour.

import { Scene } from 'cseen';
import { bars } from 'cseen/charts';
const s = new Scene({ view: 'front', size: [420, 262], padding: 6 });
s.add(bars({
data: { Web: [12, 19, 7, 15], App: [8, 11, 14, 9] },
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
title: 'Signups',
}));

Each series takes the next series colour, which is the accent turned around the colour wheel. Change the theme and the chart follows.

Grouped bars
Grouped barsA map of series gives side-by-side bars and a legend.Grouped0510152025JanFebMarAprMayJunWebApp

Drag to turn, scroll or pinch to zoom, double click to reset.

A palette is a name or a list of roles and colours:

import { Scene } from 'cseen';
import { donut, bars } from 'cseen/charts';
const s = new Scene({ view: 'front', size: [420, 262], padding: 6 });
s.add(donut({
data: [['Done', 70], ['Open', 20], ['Blocked', 10]],
palette: ['accent', 's2', 'faint'], // roles, so they still follow the theme
labelValues: true,
}));
  • palette: 'sequential' runs one hue from light to strong, for values.
  • palette: 'diverging' runs two hues around zero.
  • highlight: 2 picks one bar out in the accent and greys the rest.
import { Scene } from 'cseen';
import { bars } from 'cseen/charts';
const s = new Scene({ view: 'front', size: [420, 262], padding: 6 });
s.add(bars({
data: [['Rust', 82], ['Go', 64], ['TypeScript', 91], ['Python', 77]],
horizontal: true,
labelValues: true,
highlight: 2,
}));
Horizontal bars
Horizontal barsLabel and value pairs, with one bar picked out.020406080100Rust82Go64TypeScript91Python77

Drag to turn, scroll or pinch to zoom, double click to reset.

A chart has a grow property from 0 to 1 and a data property that tweens between datasets. Put it in a scene and it stands up:

A chart in a scene
A chart in a sceneA chart is a plane in the scene. It grows in, then morphs to new numbers.Revenue0510152025Q1Q2Q3Q420232024

Drag to turn, scroll or pinch to zoom, double click to reset.

A chart is a plane, so it can sit on a device:

A dashboard on a screen
A dashboard on a screenFour charts put on a monitor like any other element.Traffic2468101212345678WebAppAPIABCDE

Drag to turn, scroll or pinch to zoom, double click to reset.