Gallery / Change and ranking /
Dumbbell and lollipop
A change between two values per category (dumbbell); a value per category, lighter than a bar (lollipop).
69.2 KB of code · core 29.5 + 10 blocks 39.7
Customer satisfaction, 2024 (grey) and 2025 (blue)
Satisfaction rose in four of the five regions, most in East (+13); only South fell, from 48 to 45.
How it is made: A dumbbell: a rule from x to x2 along the middle of each band, and two point marks at its ends. It shows the gap and its direction better than two bars side by side.
On a page of its own this chart would need 10 blocks, 69.2 KB with the core:
Net promoter score by product
The mobile app has the highest score, 54; onboarding the lowest, 15.
How it is made: A lollipop: a rule from a constant x2 of 0 to the value, and a point at its end. Lighter than a bar when there are many categories.
On a page of its own this chart would need 10 blocks, 69.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: 10 of the 59, 69.2 KB of code, minified, which is 32% 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 76.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.linear Numbers to positions, with round ticks. | Numbers to positions, with round ticks. | 1.6 | |
mark.point Dots, bubbles and beeswarms. | Dots, bubbles and beeswarms. | 3.9 | |
mark.rule Target and threshold lines; the target tick of a bullet chart. | Target and threshold lines; the target tick of a bullet chart. | 3.8 | |
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 | |
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 10 blocks 39.7 | 69.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/dumbbell.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
dumbbell.json
{
"title": "Dumbbell and lollipop",
"data": {
"regions": [
{ "region": "North", "y2024": 62, "y2025": 71 },
{ "region": "South", "y2024": 48, "y2025": 45 },
{ "region": "East", "y2024": 55, "y2025": 68 },
{ "region": "West", "y2024": 70, "y2025": 74 },
{ "region": "Central", "y2024": 41, "y2025": 52 }
],
"nps": [
{ "product": "Mobile app", "score": 54 },
{ "product": "Web app", "score": 47 },
{ "product": "Support", "score": 38 },
{ "product": "Billing", "score": 22 },
{ "product": "Onboarding", "score": 15 }
]
},
"charts": [
{
"title": "Customer satisfaction, 2024 (grey) and 2025 (blue)",
"note": "Satisfaction rose in four of the five regions, most in East (+13); only South fell, from 48 to 45.",
"how": "A dumbbell: a rule from x to x2 along the middle of each band, and two point marks at its ends. It shows the gap and its direction better than two bars side by side.",
"spec": {
"data": "regions",
"size": [640, 280],
"scales": { "y": { "type": "band" }, "x": { "type": "linear", "zero": true } },
"guides": [
{ "type": "grid", "scale": "x" },
{ "type": "axis", "scale": "y" },
{ "type": "axis", "scale": "x" }
],
"marks": [
{ "type": "rule", "x": "y2024", "x2": "y2025", "y": "region", "stroke": "var(--bc-axis, #cbd2dc)", "strokeWidth": 3 },
{ "type": "point", "x": "y2024", "y": "region", "r": 6, "fill": "var(--bc-label, #94a3b8)" },
{ "type": "point", "x": "y2025", "y": "region", "r": 6, "fill": "var(--bc-c0, #3a6fe4)" }
],
"interaction": [{ "type": "tooltip", "fields": ["y2024", "y2025"], "labels": { "y2024": "2024", "y2025": "2025" } }]
}
},
{
"title": "Net promoter score by product",
"note": "The mobile app has the highest score, 54; onboarding the lowest, 15.",
"how": "A lollipop: a rule from a constant x2 of 0 to the value, and a point at its end. Lighter than a bar when there are many categories.",
"spec": {
"data": "nps",
"size": [640, 260],
"scales": { "y": { "type": "band" }, "x": { "type": "linear", "zero": true } },
"guides": [
{ "type": "grid", "scale": "x" },
{ "type": "axis", "scale": "y" },
{ "type": "axis", "scale": "x" }
],
"marks": [
{ "type": "rule", "x": "score", "x2": { "value": 0 }, "y": "product", "stroke": "var(--bc-c0, #3a6fe4)", "strokeWidth": 2 },
{ "type": "point", "x": "score", "y": "product", "r": 6, "fill": "var(--bc-c0, #3a6fe4)" }
],
"interaction": [{ "type": "tooltip", "fields": ["score"], "labels": { "score": "NPS" } }]
}
}
]
}
The report the composer makes from it is one standalone file (76.4 KB): open it from disk, mail it, print it.
In a page of your own
The charts above use the composition kit (54.9 KB gzipped), the smallest one that has the blocks this example needs:
lib.pointer, lib.ticks, scale.band, scale.linear, mark.point, mark.rule, guide.axis, guide.grid, 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/composition.js"></script>
<script type="application/json" id="bc-data">
{"regions":[{"region":"North","y2024":62,"y2025":71},{"region":"South","y2024":48,"y2025":45},{"region":"East","y2024":55,"y2025":68},{"region":"West","y2024":70,"y2025":74},{"region":"Central","y2024":41,"y2025":52}],"nps":[{"product":"Mobile app","score":54},{"product":"Web app","score":47},{"product":"Support","score":38},{"product":"Billing","score":22},{"product":"Onboarding","score":15}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "regions",
"size": [
640,
280
],
"scales": {
"y": {
"type": "band"
},
"x": {
"type": "linear",
"zero": true
}
},
"guides": [
{
"type": "grid",
"scale": "x"
},
{
"type": "axis",
"scale": "y"
},
{
"type": "axis",
"scale": "x"
}
],
"marks": [
{
"type": "rule",
"x": "y2024",
"x2": "y2025",
"y": "region",
"stroke": "var(--bc-axis, #cbd2dc)",
"strokeWidth": 3
},
{
"type": "point",
"x": "y2024",
"y": "region",
"r": 6,
"fill": "var(--bc-label, #94a3b8)"
},
{
"type": "point",
"x": "y2025",
"y": "region",
"r": 6,
"fill": "var(--bc-c0, #3a6fe4)"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"y2024",
"y2025"
],
"labels": {
"y2024": "2024",
"y2025": "2025"
}
}
],
"alt": "Customer satisfaction, 2024 (grey) and 2025 (blue)"
}
</script>
<script type="application/json" data-bc-chart>
{
"data": "nps",
"size": [
640,
260
],
"scales": {
"y": {
"type": "band"
},
"x": {
"type": "linear",
"zero": true
}
},
"guides": [
{
"type": "grid",
"scale": "x"
},
{
"type": "axis",
"scale": "y"
},
{
"type": "axis",
"scale": "x"
}
],
"marks": [
{
"type": "rule",
"x": "score",
"x2": {
"value": 0
},
"y": "product",
"stroke": "var(--bc-c0, #3a6fe4)",
"strokeWidth": 2
},
{
"type": "point",
"x": "score",
"y": "product",
"r": 6,
"fill": "var(--bc-c0, #3a6fe4)"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"score"
],
"labels": {
"score": "NPS"
}
}
],
"alt": "Net promoter score by product"
}
</script>