chartletv0.21.0chartlet.casoon.de

Customize

Every color of a chart is a CSS custom property, such as --chartlet-accent. A token is that name without its prefix: accent, text, color-1. All five ways below set tokens, so you learn one set of names and choose where to write them down. The guide lists every token.

1. A bundled theme

light, dark and, for diagrams, blueprint ship with chartlet as theme files, the same kind of file you write yourself in way 3. Choose one in the specification or when rendering.

{ "schemaVersion": 1, "type": "bar", "title": "Monthly revenue", "theme": "dark", … }
chartlet render revenue.json --theme dark
chartlet render release-flow.json --theme blueprint
Monthly revenue
Monthly revenueRevenue increased in February and remained above January in March.050100150200Revenue in thousandsJanuary: 120120JanuaryFebruary: 180180FebruaryMarch: 150150MarchMonth

Source: Example data

Show chart data
Data for Monthly revenue
CategoryValue
January120
February180
March150
Focus
From commit to release
From commit to releaseFlow chart with 10 steps and 11 connections in 3 lanes: Development, Continuous integration and Operations. Main path: Commit pushed → Code review → Build → Run tests → All green? → Deploy to staging → Approved? → Deploy to production → Released. Loop: Code review → Build → Run tests → All green? → Deploy to staging → Approved? → Code review. Bottleneck: Approved?; without it the diagram falls apart. Commit pushed (start) in Development: leads to Code review. Code review in Development: leads to Build (merged). Build in Continuous integration: leads to Run tests. Run tests in Continuous integration: leads to All green?. All green? (decision) in Continuous integration: leads to Deploy to staging (yes) and Fix failures (no). Fix failures in Development: leads to Build (retry). Deploy to staging in Operations: leads to Approved?. Approved? (decision) in Operations: leads to Deploy to production (yes) and Code review (changes requested). Deploy to production in Operations: leads to Released. Released (end) in Operations: no further step. Group "Quality gates": Build, Run tests, All green?.DevelopmentContinuous integrationOperationsQuality gatesCommit pushed → Code reviewCode review → Build: mergedBuild → Run testsRun tests → All green?All green? → Deploy to staging: yesAll green? → Fix failures: noFix failures → Build: retryDeploy to staging → Approved?Approved? → Deploy to production: yesApproved? → Code review: changes requestedDeploy to production → Releasedmergedyesnoretryyeschanges requestedCommit pushedCommit pushedCode reviewCode reviewBuild – locked inputsBuildlocked inputsRun testsRun testsAll green?All green?Fix failuresFix failuresDeploy to stagingDeploy to stagingApproved?Approved?Deploy to productionDeploy to productionReleasedReleased

Source: Team handbook, release process

Show chart data
Data for From commit to release
StepKindLaneGroupLeads to
Commit pushedstartDevelopmentCode review
Code reviewstepDevelopmentBuild (merged)
BuildstepContinuous integrationQuality gatesRun tests
Run testsstepContinuous integrationQuality gatesAll green?
All green?decisionContinuous integrationQuality gatesDeploy to staging (yes), Fix failures (no)
Fix failuresstepDevelopmentBuild (retry)
Deploy to stagingstepOperationsApproved?
Approved?decisionOperationsDeploy to production (yes), Code review (changes requested)
Deploy to productionstepOperationsReleased
ReleasedendOperations

2. Tokens in the specification

tokens sets single colors of one chart, on top of its theme. An unknown name or a value that is not a color is refused with invalid_token.

{
  "schemaVersion": 1,
  "type": "bar",
  "title": "Monthly revenue",
  "tokens": { "accent": "#c2410c", "grid": "#ecd9cc" },
  "data": [ … ]
}
Monthly revenue
Monthly revenueRevenue increased in February and remained above January in March.050100150200Revenue in thousandsJanuary: 120120JanuaryFebruary: 180180FebruaryMarch: 150150MarchMonth

Source: Example data

Show chart data
Data for Monthly revenue
CategoryValue
January120
February180
March150

3. A theme file for many charts

A theme file names the theme to start from and the tokens that differ. Link it when you render and every chart shares the look, whatever its type; here the same file colors a bar chart, a time series and a flow chart. A specification keeps the last word: a token it sets itself wins over the file.

brand.json
{
  "$schema": "../../schema/chartlet-theme.schema.json",
  "theme": "light",
  "tokens": {
    "text": "#1f2a1f",
    "muted": "#46564a",
    "grid": "#d7e2d3",
    "zero": "#6b7d6f",
    "accent": "#0f766e",
    "color-1": "#0f766e",
    "color-2": "#c2410c",
    "color-3": "#4d7c0f",
    "color-4": "#1f2a1f",
    "role-blue": "#0f766e",
    "role-blue-fill": "#e6f4f1",
    "role-amber": "#b45309",
    "role-amber-fill": "#fff4e0"
  }
}
chartlet render revenue.json --theme brand.json
chartlet render channels.json --theme brand.json
chartlet render release-flow.json --theme brand.json
import { renderChart } from '@casoon/chartlet';
import brand from './brand.json' with { type: 'json' };

const { content } = renderChart(spec, { theme: brand });
Monthly revenue
Monthly revenueRevenue increased in February and remained above January in March.050100150200Revenue in thousandsJanuary: 120120JanuaryFebruary: 180180FebruaryMarch: 150150MarchMonth

Source: Example data

Show chart data
Data for Monthly revenue
CategoryValue
January120
February180
March150
Series
Revenue by channel
Revenue by channelDirect revenue grew every quarter and stayed the largest channel.0200400600Revenue in thousandsDirectPartnersMarketplaceQ1 – Direct: 420420Q1 – Partners: 180180Q1 – Marketplace: 9696Q1Q2 – Direct: 455455Q2 – Partners: 205205Q2 – Marketplace: 8888Q2Q3 – Direct: 480480Q3 – Partners: 198198Q3 – Marketplace: 121121Q3Q4 – Direct: 512512Q4 – Partners: 236236Q4 – Marketplace: 140140Q4Quarter

Source: Example data

Show chart data
Data for Revenue by channel
CategoryDirectPartnersMarketplace
Q142018096
Q245520588
Q3480198121
Q4512236140
Focus
From commit to release
From commit to releaseFlow chart with 10 steps and 11 connections in 3 lanes: Development, Continuous integration and Operations. Main path: Commit pushed → Code review → Build → Run tests → All green? → Deploy to staging → Approved? → Deploy to production → Released. Loop: Code review → Build → Run tests → All green? → Deploy to staging → Approved? → Code review. Bottleneck: Approved?; without it the diagram falls apart. Commit pushed (start) in Development: leads to Code review. Code review in Development: leads to Build (merged). Build in Continuous integration: leads to Run tests. Run tests in Continuous integration: leads to All green?. All green? (decision) in Continuous integration: leads to Deploy to staging (yes) and Fix failures (no). Fix failures in Development: leads to Build (retry). Deploy to staging in Operations: leads to Approved?. Approved? (decision) in Operations: leads to Deploy to production (yes) and Code review (changes requested). Deploy to production in Operations: leads to Released. Released (end) in Operations: no further step. Group "Quality gates": Build, Run tests, All green?.DevelopmentContinuous integrationOperationsQuality gatesCommit pushed → Code reviewCode review → Build: mergedBuild → Run testsRun tests → All green?All green? → Deploy to staging: yesAll green? → Fix failures: noFix failures → Build: retryDeploy to staging → Approved?Approved? → Deploy to production: yesApproved? → Code review: changes requestedDeploy to production → Releasedmergedyesnoretryyeschanges requestedCommit pushedCommit pushedCode reviewCode reviewBuild – locked inputsBuildlocked inputsRun testsRun testsAll green?All green?Fix failuresFix failuresDeploy to stagingDeploy to stagingApproved?Approved?Deploy to productionDeploy to productionReleasedReleased

Source: Team handbook, release process

Show chart data
Data for From commit to release
StepKindLaneGroupLeads to
Commit pushedstartDevelopmentCode review
Code reviewstepDevelopmentBuild (merged)
BuildstepContinuous integrationQuality gatesRun tests
Run testsstepContinuous integrationQuality gatesAll green?
All green?decisionContinuous integrationQuality gatesDeploy to staging (yes), Fix failures (no)
Fix failuresstepDevelopmentBuild (retry)
Deploy to stagingstepOperationsApproved?
Approved?decisionOperationsDeploy to production (yes), Code review (changes requested)
Deploy to productionstepOperationsReleased
ReleasedendOperations

4. The CSS of the host page

A chart inlined in a page reads its colors from the page, so the page can set the same properties. Nothing in the specification changes. This works for HTML and inline SVG; an image or a PDF cannot see the page, which is what ways 2 and 3 are for.

.host .chartlet-root {
  --chartlet-accent: #7c3aed;
  --chartlet-grid: #e4dcf5;
}
Monthly revenue
Monthly revenueRevenue increased in February and remained above January in March.050100150200Revenue in thousandsJanuary: 120120JanuaryFebruary: 180180FebruaryMarch: 150150MarchMonth

Source: Example data

Show chart data
Data for Monthly revenue
CategoryValue
January120
February180
March150

5. Every chart of a folder, in print too

Because the theme file stays outside the specifications, a folder of charts gets one look with a loop, and changing the file restyles all of them. Tokens also reach the print and social variants and PNG output, which resolve every color to a literal value: the chart below is the print variant with the same file.

for spec in charts/*.json; do
  chartlet render "$spec" --theme brand.json -o "out/$(basename "$spec" .json).svg"
done
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { renderChart } from '@casoon/chartlet';

const brand = JSON.parse(readFileSync('brand.json', 'utf8'));
for (const file of readdirSync('charts').filter((name) => name.endsWith('.json'))) {
  const spec = JSON.parse(readFileSync(`charts/${file}`, 'utf8'));
  const { content } = renderChart(spec, { format: 'svg', theme: brand });
  writeFileSync(`out/${file.replace('.json', '.svg')}`, content);
}
Monthly revenueRevenue increased in February and remained above January in March.Monthly revenue050100150200Revenue in thousandsJanuary: 120120JanuaryFebruary: 180180FebruaryMarch: 150150MarchMonth