Repository navigation
How Charts Are Picked And Built
This page describes what cw.py does with your data and your question, read from the source of version 0.8.4 and shown with real runs. The commands themselves, with every option, are on Commands.
cw.py finds the knowledge base from its own location: kb/ beside the scripts/ folder it sits in. It does not depend on the folder you run it from. File arguments (--data, --in, --out) are read relative to the folder you run it from.
data reads the first row as column names and gives each column one of three kinds:
| Kind | When | Reported |
|---|---|---|
time |
every non-empty cell looks like 2026, 2026-03, 2026-03-01, any of those with a time (2026-03-01 14:30, 2026-03-01T14:30:00), a quarter (2026-Q1) or a slash date (3/1/26, 03/01/2026) |
first, last
|
q (a number) |
every non-empty cell is a number once commas are removed, so 1,200 counts as 1200 |
min, max
|
n (a name) |
anything else | how many distinct values, and up to eight of them in sorted order |
Empty cells are left out of the test, and a byte order mark at the start of the file is ignored. shape_guess is the kinds joined with commas, in column order: the shape pick takes.
first and last are the smallest and largest cells in text order, not in time order. Mixed date formats make that visible, as in this mixed.csv.
month,units,note
2026-Q1,"1,200",ok
2026-Q2,980,
03/01/2026,1100,latedata reports:
$ python scripts/cw.py data mixed.csv
{
"file": "mixed.csv",
"rows": 3,
"columns": [
{
"name": "month",
"kind": "time",
"non_empty": 3,
"first": "03/01/2026",
"last": "2026-Q2"
},
{
"name": "units",
"kind": "q",
"non_empty": 3,
"min": 980.0,
"max": 1200.0
},
{
"name": "note",
"kind": "n",
"non_empty": 2,
"distinct": 2,
"sample": [
"late",
"ok"
]
}
],
"shape_guess": "time,q,n"
}data always prints JSON, with or without --json.
pick scores every chart type in the knowledge base that is not marked deprecated, and prints the top three (--top changes that). Each chart file lists a name and aliases, "goal" words, the data shapes it takes, soft limits on series and categories, and a support level per target. It also names a family. The families come from the Financial Times Visual Vocabulary (deviation, correlation, ranking, distribution, change over time, magnitude, part-to-whole, spatial, flow), plus hierarchy, relationship, single value and table.
Your question is lower-cased and split into words. Small words (a, the, of, show, chart, graph, plot and the like) are dropped. 114 common words are then expanded into goal words: "trend" adds "over time", "funnel" adds "flow" and "stages", "share" adds "part-to-whole", "price" adds "over time". The scores add up as follows:
| Match | Points |
|---|---|
| The chart's name, an alias or its slug appears in the question as a whole word | +6 |
| Each distinct goal word that matches one of the chart's goals | +1.5 |
| The question's words include the chart's family | +3 (+1.5 for a secondary family) |
--shape equals one of the chart's shapes |
+3 |
--shape matches apart from a trailing *n (several series) |
+1.5 |
--shape given and matches none of the chart's shapes |
−3 |
--series above the chart's limit, or --categories above its limit |
−2 each, with a warning |
--target cannot draw it / only as a picture / only approximately |
−4 / −1 / −0.5, with a warning |
| Evidence high / medium | +0.5 / +0.25 |
| Popularity core / common or rising / declining | +0.5 / +0.25 / −0.5 |
Ties sort by slug. Charts scoring zero or less are dropped.
Naming the chart counts most:
$ python scripts/cw.py pick --question "a sankey of where visitors go"
1. sankey (8.0): Sankey diagram - How do quantities flow from sources to destinations, and where do they end up?
why: named in request; goals: where
2. bubble-map (2.25): Bubble map - How much of something is at each place?
why: goals: where
3. choropleth (2.25): Choropleth map - How does a rate or ratio vary across regions?
why: goals: whereThe limits and the target turn into warnings, and lower the score:
$ python scripts/cw.py pick --question "trend over time" --shape time,q*n --series 8 --target mermaid
1. line (8.0): Line chart - How does a value change over time, and how do a few series compare as they change?
why: goals: over, over time, time, trend; shape time,q*n
warn: 8 series > cap 5: facet (small multiples) or fold to Other
2. bump (7.0): Bump chart - How did the rank order of a set of entities change across several periods?
why: goals: over, over time, time; shape time,q*n
warn: mermaid: image only
3. column (6.5): Column chart - How much was there in each period, and how do the totals compare period to period?
why: goals: over, over time, time; shape time,q*n
warn: 8 series > cap 3: facet (small multiples) or fold to OtherA shape alone narrows the field but cannot rank inside it, so it is worth giving the question too:
$ python scripts/cw.py pick --shape n,q
1. bar (4.0): Bar chart - How big is each category, and which is largest?
why: shape n,q
2. column (4.0): Column chart - How much was there in each period, and how do the totals compare period to period?
why: shape n,q
3. diverging-bar (4.0): Diverging bar chart - Which categories are above or below a reference (zero, target, average), and by how much?
why: shape n,qThe evidence and popularity points mean a well-established chart always scores above zero, so pick returns three charts even for a question it does not understand:
$ python scripts/cw.py pick --question "zzz"
1. bar (1.0): Bar chart - How big is each category, and which is largest?
2. column (1.0): Column chart - How much was there in each period, and how do the totals compare period to period?
3. diverging-bar (1.0): Diverging bar chart - Which categories are above or below a reference (zero, target, average), and by how much?The "no match" message in the source (which suggests chartwright-curate) does not appear in practice. A top pick with an empty why line means nothing matched. The skill then reads the chart entries instead of trusting the score.
build reads the CSV, checks that each column you named exists, and writes the chart for one target: a Mermaid block, a JSON spec, a Python script, a URL or plain text. It prints to standard output, or with --out writes the file and prints wrote <file> (<n> chars). Which charts each target builds is on Render targets.
Title. --title sets it. Without one the title is <y> by <x>, as in "sales by region". The skill passes the claim the chart supports ("South leads on sales").
Repeated x values are combined. When an x value appears more than once within a series, the rows are summed, and a note goes to standard error. --agg mean averages them, and --agg none keeps every row. With sales.csv holding two products per region:
$ python scripts/cw.py build --chart bar --target terminal --data sales.csv --x region --y sales
note: duplicate region values aggregated by sum (6 rows -> 3 points)
sales by region
North ███████████████████████████ 200
South ██████████████████████████████ 225
East █████████████████ 130
$ python scripts/cw.py build --chart bar --target terminal --data sales.csv --x region --y sales --agg mean
note: duplicate region values aggregated by mean (6 rows -> 3 points)
sales by region
North ███████████████████████████ 100
South ██████████████████████████████ 112.5
East █████████████████ 65Because the note goes to standard error, redirecting standard output into a file keeps it out of the chart.
Mermaid bars start at zero. Mermaid's xychart scales its axis to the data and so can cut off the bottom of a bar. For bar and column charts with no negative values, build writes the axis from 0 to a round number at or above the largest value (225 gives 250, 130 gives 150). Line charts keep Mermaid's own scaling.
Several series in Mermaid. xychart-beta has no legend, so build names the series in order in a comment. Mermaid 11.16 and later can name each series, which --flag namedSeries turns on. It is off by default to suit hosts on older Mermaid versions. With --series product:
$ python scripts/cw.py build --chart grouped-bar --target mermaid --data sales.csv --x region --y sales --series product
```mermaid
%% xychart has no legend: series in order are A, B
xychart-beta
title "sales by region"
x-axis ["North", "South", "East"]
y-axis "sales" 0 --> 150
bar [120, 95, 60]
bar [80, 130, 70]
```
$ python scripts/cw.py build --chart grouped-bar --target mermaid --data sales.csv --x region --y sales --series product --flag namedSeries
```mermaid
xychart
title "sales by region"
x-axis ["North", "South", "East"]
y-axis "sales" 0 --> 150
bar "A" [120, 95, 60]
bar "B" [80, 130, 70]
```Column roles for composed charts. Charts built from more than one mark take the columns in fixed roles. --y2 names a second number column.
| Chart | --x |
--y |
--y2 |
--series |
|---|---|---|---|---|
| dumbbell (wide) | category | first value | second value | |
| dumbbell (long) | category | value | which end (two values) | |
| slope | period | value | entity | |
| waterfall | step | signed change | ||
| small-multiples | panel | |||
| sankey, alluvial | source | weight | target | |
| heatmap | column | value | row | |
| quadrant | label | |||
| bullet | measure | actual | target | poor band (optional) |
| range-band | time | lower | upper | centre line (optional) |
| connected-scatter | first measure | second measure | time label | |
| bump | period | rank | entity | |
| d2 network, tree | source or child | target or parent |
render turns what build wrote into the final file. For Vega-Lite it calls vl-convert in the same process. For Mermaid it runs mmdc, or npx with the pinned Mermaid CLI, on the block it pulls out of a Markdown file, and deletes the .mmd it made for that. The matplotlib, PowerPoint, Excel and Word scripts run under the same Python, in the output file's folder. The name the script writes (--png at build time) therefore lands there. For the web targets it wraps the spec in a page. It prints wrote <file> (<n> bytes) when the file exists afterwards, and otherwise a message.
Every command prints problems as a line of text and exits 0, so an agent can read the message and carry on. With --strict the same problems exit 1. --strict and --json can go before or after the command name. Only argument errors caught by argparse (a missing required option, an unknown command) always exit 2. The messages are listed on Commands.
This wiki describes chartwright 0.8.4 (tag v0.8.4, commit 34b1871) and was last updated on 2026-10-03. The plugin is MIT licensed. Report problems in the issues.
Using it
- Getting started
- How the skills work
- How charts are picked and built
- Render targets
- Commands
- Recipes
- Works with
- FAQ
The releases
Contributing
Elsewhere