Gallery / Comparing categories /
One bar set apart
One bar set apart (the best month), and a tile that names it.
73.2 KB of code · core 29.5 + 12 blocks 43.7
Best month
How it is made: The tile finds the month itself: rowField names the row of the maximum.
On a page of its own this chart would need 2 blocks, 38.3 KB with the core:
Revenue by month
September was the best month of the year, January the weakest.
How it is made: transform.highlight writes which bar is the best; a color scale of two colors sets it apart, and the bar moves by itself when the data changes.
On a page of its own this chart would need 11 blocks, 68.2 KB with the core:
What the report is made of
The composer reads the JSON below and puts into the page the core and only the blocks its charts use: 12 of the 59, 73.2 KB of code, minified, which is 34% of the 215.9 KB that the core and every block weigh together. A block that two charts use is carried once. The report file is 80.4 KB: that code, the data, the styles and the page around them.
| Block | What it does | Share of the code | KB |
|---|---|---|---|
core.composed-plain A report with plain data: no checks, no decoder. Most reports. | A report with plain data: no checks, no decoder. Most reports. | 29.5 | |
lib.pointer Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush. | Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush. | 1.7 | |
lib.ticks Round steps and ticks (1, 2 or 5 × 10ⁿ). Shared by the number scales and the histogram bins. | Round steps and ticks (1, 2 or 5 × 10ⁿ). Shared by the number scales and the histogram bins. | 0.7 | |
scale.band One band per category: the axis of bar charts. | One band per category: the axis of bar charts. | 1.2 | |
scale.color A color per category, from the theme palette. | A color per category, from the theme palette. | 0.8 | |
scale.linear Numbers to positions, with round ticks. | Numbers to positions, with round ticks. | 1.6 | |
transform.highlight Marks one row to set apart: the best month, the largest region. | Marks one row to set apart: the best month, the largest region. | 1.4 | |
mark.rect Rectangles: bars, grouped bars, ranges, heatmap cells; the hexagons of a hexbin. | Rectangles: bars, grouped bars, ranges, heatmap cells; the hexagons of a hexbin. | 4.5 | |
guide.axis Axes: formatted labels, a title, long categories wrapped. | Axes: formatted labels, a title, long categories wrapped. | 11.7 | |
guide.grid Grid lines at the ticks. | Grid lines at the ticks. | 0.6 | |
guide.kpi A KPI tile: the figure, its change, a sparkline. | A KPI tile: the figure, its change, a sparkline. | 4.9 | |
interaction.tooltip The values under the pointer. | The values under the pointer. | 10.7 | |
renderer.svg Draws into SVG: sharp, selectable, prints well. The default. | Draws into SVG: sharp, selectable, prints well. The default. | 3.9 | |
| Total | The core 29.5 and 12 blocks 43.7 | 73.2 |
The JSON
This is the whole input. data holds the datasets, each chart is a spec that names one.
In a checkout of the repository: node scripts/compose.js skills/blockcharts/recipes/highlight-bar.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
highlight-bar.json
{
"title": "One bar set apart",
"data": {
"months": [
{
"month": "2025-01-01",
"revenue": 785400
},
{
"month": "2025-02-01",
"revenue": 1112400
},
{
"month": "2025-03-01",
"revenue": 1038500
},
{
"month": "2025-04-01",
"revenue": 896400
},
{
"month": "2025-05-01",
"revenue": 862100
},
{
"month": "2025-06-01",
"revenue": 990200
},
{
"month": "2025-07-01",
"revenue": 1066300
},
{
"month": "2025-08-01",
"revenue": 996000
},
{
"month": "2025-09-01",
"revenue": 1257800
},
{
"month": "2025-10-01",
"revenue": 1224500
},
{
"month": "2025-11-01",
"revenue": 1198100
},
{
"month": "2025-12-01",
"revenue": 1039100
}
]
},
"charts": [
{
"title": "Best month",
"how": "The tile finds the month itself: rowField names the row of the maximum.",
"span": 1,
"spec": {
"data": "months",
"size": [
280,
84
],
"padding": {
"top": 8,
"bottom": 4,
"left": 0,
"right": 0
},
"scales": {},
"guides": [
{
"type": "kpi",
"field": "revenue",
"aggregate": "max",
"compare": "none",
"label": "Best month",
"rowField": "month",
"rowFormat": {
"month": "long",
"timeZone": "UTC"
},
"format": {
"maximumFractionDigits": 0
}
}
],
"marks": []
}
},
{
"title": "Revenue by month",
"note": "September was the best month of the year, January the weakest.",
"how": "transform.highlight writes which bar is the best; a color scale of two colors sets it apart, and the bar moves by itself when the data changes.",
"span": 3,
"spec": {
"data": "months",
"size": [
640,
300
],
"transforms": [
{
"type": "highlight",
"field": "revenue",
"pick": "max",
"yes": "best",
"no": "other"
}
],
"scales": {
"x": {
"type": "band"
},
"y": {
"type": "linear",
"zero": true
},
"c": {
"type": "color",
"domain": [
"other",
"best"
],
"range": [
"#94a3b8",
"#2563eb"
]
}
},
"guides": [
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x",
"format": {
"month": "short",
"timeZone": "UTC"
},
"count": 12,
"anchor": "end"
},
{
"type": "axis",
"scale": "y",
"format": "compact"
}
],
"marks": [
{
"type": "rect",
"x": "month",
"y": "revenue",
"color": {
"field": "highlight",
"scale": "c"
}
}
],
"interaction": [
{
"type": "tooltip",
"fields": ["revenue"],
"labels": { "revenue": "Revenue" },
"formats": {
"month": { "month": "long", "year": "numeric", "timeZone": "UTC" },
"revenue": { "style": "currency", "currency": "USD", "maximumFractionDigits": 0 }
}
}
]
}
}
],
"layout": {
"columns": 4
}
} The report the composer makes from it is one standalone file (80.4 KB): open it from disk, mail it, print it.
In a page of your own
The charts above use the full kit (81.8 KB gzipped), the smallest one that has the blocks this example needs:
lib.pointer, lib.ticks, scale.band, scale.color, scale.linear, transform.highlight, mark.rect, guide.axis, guide.grid, guide.kpi, interaction.tooltip, renderer.svg.
The HTML below loads it from the jsDelivr CDN, pinned to version 0.0.5; to serve it from your own site, put its file there
(the files of a release) and change the address.
HTML
<script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.5/release/kits/full.js"></script>
<script type="application/json" id="bc-data">
{"months":[{"month":"2025-01-01","revenue":785400},{"month":"2025-02-01","revenue":1112400},{"month":"2025-03-01","revenue":1038500},{"month":"2025-04-01","revenue":896400},{"month":"2025-05-01","revenue":862100},{"month":"2025-06-01","revenue":990200},{"month":"2025-07-01","revenue":1066300},{"month":"2025-08-01","revenue":996000},{"month":"2025-09-01","revenue":1257800},{"month":"2025-10-01","revenue":1224500},{"month":"2025-11-01","revenue":1198100},{"month":"2025-12-01","revenue":1039100}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "months",
"size": [
280,
84
],
"padding": {
"top": 8,
"bottom": 4,
"left": 0,
"right": 0
},
"scales": {},
"guides": [
{
"type": "kpi",
"field": "revenue",
"aggregate": "max",
"compare": "none",
"label": "Best month",
"rowField": "month",
"rowFormat": {
"month": "long",
"timeZone": "UTC"
},
"format": {
"maximumFractionDigits": 0
}
}
],
"marks": [],
"alt": "Best month"
}
</script>
<script type="application/json" data-bc-chart>
{
"data": "months",
"size": [
640,
300
],
"transforms": [
{
"type": "highlight",
"field": "revenue",
"pick": "max",
"yes": "best",
"no": "other"
}
],
"scales": {
"x": {
"type": "band"
},
"y": {
"type": "linear",
"zero": true
},
"c": {
"type": "color",
"domain": [
"other",
"best"
],
"range": [
"#94a3b8",
"#2563eb"
]
}
},
"guides": [
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x",
"format": {
"month": "short",
"timeZone": "UTC"
},
"count": 12,
"anchor": "end"
},
{
"type": "axis",
"scale": "y",
"format": "compact"
}
],
"marks": [
{
"type": "rect",
"x": "month",
"y": "revenue",
"color": {
"field": "highlight",
"scale": "c"
}
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"revenue"
],
"labels": {
"revenue": "Revenue"
},
"formats": {
"month": {
"month": "long",
"year": "numeric",
"timeZone": "UTC"
},
"revenue": {
"style": "currency",
"currency": "USD",
"maximumFractionDigits": 0
}
}
}
],
"alt": "Revenue by month"
}
</script>