Tables¶
A table is the right picture when the reader needs the exact values. tools.charts.table draws a publication data-graphic table: one measured SVG, a PNG, and a self-contained HTML table whose headers sort, whose rows filter and whose numbers copy out as TSV.
Every write is a plan and a commit. tools.charts.plan_table previews the files and changes; tools.charts.table takes the plan's id and writes exactly what the plan showed.
A first table¶
{
"data": {
"rows": [
{ "region": "North", "quarter": "Q1", "revenue": 510, "change": 0.12, "target": 540 },
{ "region": "South", "quarter": "Q1", "revenue": 390, "change": -0.04, "target": 420 },
{ "region": "North", "quarter": "Q2", "revenue": 540, "change": 0.06, "target": 560 },
{ "region": "South", "quarter": "Q2", "revenue": 420, "change": 0.08, "target": 450 }
]
},
"columns": [
{ "field": "region", "label": "Region" },
{ "field": "quarter", "label": "Quarter" },
{ "field": "revenue", "label": "Revenue", "format": "currency", "align": "right", "cell": "bar" },
{ "field": "change", "label": "Change", "format": "percent", "decimals": 1, "cell": "delta", "align": "right" },
{ "field": "revenue", "label": "Against target", "cell": "bullet", "targetField": "target", "align": "right" }
],
"title": "Regional revenue",
"subtitle": "Quarter to date against the plan",
"kicker": "Finance",
"source": "Source: finance close",
"rowGroupField": "region",
"summaryRow": { "label": "Total", "operations": { "revenue": "sum" } },
"sortBy": { "field": "revenue", "order": "desc" },
"formats": ["svg", "png", "html"]
}
Pass it to tools.charts.plan_table, inspect output.files, then commit with tools.charts.table.
Columns¶
Each column names one field of a row:
| Key | Does |
|---|---|
field | The row key the column reads. Required. |
label | The header text; the field name when absent. |
spanner | A grouped header above consecutive columns that share it. |
align | left, right or center; numbers default to right. |
format | number, currency, percent, compact, integer, text or date. |
decimals | Decimal places; the values decide the default. |
width | A minimum width in px; the measured content decides the rest. |
cell | The inline mark: text, bar, sparkline, sparkarea, sparkbar, bullet, delta, badge, heatmap or dot. |
targetField | For bullet, the field of the same row that holds the target tick. |
domain | The value range of a bar, bullet or heatmap; the column's own values when absent. |
positiveIsGood | For delta, whether a rise is good news (the default is true). |
badgeColors | For badge and dot, the fill for each value, such as { "Overdue": "#CC3344" }. |
Rows¶
data takes exactly one of rows or path. A path names a workspace .csv, .tsv, .json, .jsonl or .parquet file, with an optional format and Vega-Lite transform list.
rowGroupField splits the rows into labelled sections, summaryRow adds a final row per column, sortBy sorts before the table is drawn, limit keeps the first n rows after sorting, zebra tints every other row and highlightRows tints the rows named by index or by any text value they carry.
Output¶
By default the call writes the content-sized SVG, its PNG and the resolved spec under outputs/charts/ (or the configured outDir). Add "html" to formats for a self-contained .html table: it opens offline, its headers sort, its rows filter and its numbers copy as TSV.
The SVG is measured with the bundled fonts, so no label clips, and the same rows give the same bytes on the same platform.