Gallery / Targets and progress /
Gauge and progress ring
One figure against its maximum or target: a gauge, a progress ring.
50.6 KB of code · core 29.5 + 4 blocks 21.1
Customer satisfaction, out of 100
How it is made: A gauge is mark.arc on a half circle: startAngle -90, endAngle 90. total is the maximum, so the arc fills to 72 and the rest is an empty track; center writes the figure.
On a page of its own this chart would need 4 blocks, 50.6 KB with the core:
Revenue against the $10M target
$8.3M so far, 83% of the $10M target.
How it is made: A progress ring: the same mark on a full circle, total = the target, center "percent" = the share of it.
On a page of its own this chart would need 4 blocks, 50.6 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: 4 of the 59, 50.6 KB of code, minified, which is 23% 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 56.9 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 | |
mark.arc Pie and donut slices; gauges and progress rings. | Pie and donut slices; gauges and progress rings. | 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 4 blocks 21.1 | 50.6 |
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/gauge.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
gauge.json
{
"title": "Gauge and progress ring",
"data": {
"score": [{ "metric": "Customer satisfaction", "score": 72 }],
"sales": [{ "metric": "Revenue, $M", "revenue": 8.3 }]
},
"layout": { "columns": 2 },
"charts": [
{
"title": "Customer satisfaction, out of 100",
"span": 1,
"how": "A gauge is mark.arc on a half circle: startAngle -90, endAngle 90. total is the maximum, so the arc fills to 72 and the rest is an empty track; center writes the figure.",
"spec": {
"data": "score",
"size": [360, 220],
"marks": [
{
"type": "arc",
"value": "score",
"startAngle": -90,
"endAngle": 90,
"total": 100,
"innerRadius": 0.72,
"padAngle": 0,
"center": "value",
"labelFormat": "integer",
"fill": "var(--bc-c0, #3a6fe4)"
}
],
"interaction": [{ "type": "tooltip", "fields": ["metric", "score"] }]
}
},
{
"title": "Revenue against the $10M target",
"span": 1,
"note": "$8.3M so far, 83% of the $10M target.",
"how": "A progress ring: the same mark on a full circle, total = the target, center \"percent\" = the share of it.",
"spec": {
"data": "sales",
"size": [360, 220],
"marks": [
{
"type": "arc",
"value": "revenue",
"total": 10,
"innerRadius": 0.78,
"padAngle": 0,
"center": "percent",
"fill": "var(--bc-c1, #14a39a)"
}
],
"interaction": [{ "type": "tooltip", "fields": ["metric", "revenue"] }]
}
}
]
}
The report the composer makes from it is one standalone file (56.9 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, mark.arc, 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">
{"score":[{"metric":"Customer satisfaction","score":72}],"sales":[{"metric":"Revenue, $M","revenue":8.3}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "score",
"size": [
360,
220
],
"marks": [
{
"type": "arc",
"value": "score",
"startAngle": -90,
"endAngle": 90,
"total": 100,
"innerRadius": 0.72,
"padAngle": 0,
"center": "value",
"labelFormat": "integer",
"fill": "var(--bc-c0, #3a6fe4)"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"metric",
"score"
]
}
],
"alt": "Customer satisfaction, out of 100"
}
</script>
<script type="application/json" data-bc-chart>
{
"data": "sales",
"size": [
360,
220
],
"marks": [
{
"type": "arc",
"value": "revenue",
"total": 10,
"innerRadius": 0.78,
"padAngle": 0,
"center": "percent",
"fill": "var(--bc-c1, #14a39a)"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"metric",
"revenue"
]
}
],
"alt": "Revenue against the $10M target"
}
</script>