Error bars and a confidence band
A mean with its interval (error bars); a forecast with its range (confidence band).
81.7 KB of code · core 29.5 + 14 blocks 52.2
Improvement by dose, mean and 95% interval
Every dose helped more than the placebo; 40 mg did little better than 20 mg, and its interval is wider.
How it is made: Error bars: a rule from y (low) to y2 (high) in the middle of each band, and a point at the mean. A scale that does not start at zero is fine here: the points compare positions, not lengths.
On a page of its own this chart would need 10 blocks, 69.2 KB with the core:
Orders, actual and forecast with its 80% range
Orders are forecast to reach about 184 in December, most likely between 157 and 211.
How it is made: A confidence band: an area from y (high) to y2 (low), light, under the lines. The forecast starts at the last actual month, where the band is zero wide, so the lines join. Rows without a value leave the mark out there.
On a page of its own this chart would need 11 blocks, 72.8 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: 14 of the 59, 81.7 KB of code, minified, which is 38% 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 89.7 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.curve The path of a line: straight segments, a smooth curve that never overshoots, or steps. Shared by line and area. | The path of a line: straight segments, a smooth curve that never overshoots, or steps. Shared by line and area. | 1.2 | |
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 | |
scale.time Dates to positions, ticks in days, months or years (UTC). | Dates to positions, ticks in days, months or years (UTC). | 4.1 | |
mark.area Filled areas, stacked or not. | Filled areas, stacked or not. | 2.9 | |
mark.line A line per series, with optional end labels. | A line per series, with optional end labels. | 4.4 | |
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 14 blocks 52.2 | 81.7 |
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/error-bars.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
error-bars.json
{
"title": "Error bars and a confidence band",
"data": {
"trial": [
{ "group": "Placebo", "mean": 4.1, "low": 3.2, "high": 5.0 },
{ "group": "Dose 10 mg", "mean": 5.6, "low": 4.8, "high": 6.4 },
{ "group": "Dose 20 mg", "mean": 6.9, "low": 6.0, "high": 7.9 },
{ "group": "Dose 40 mg", "mean": 7.3, "low": 6.1, "high": 8.6 }
],
"forecast": [
{ "month": "2026-01-01", "actual": 120 },
{ "month": "2026-02-01", "actual": 128 },
{ "month": "2026-03-01", "actual": 135 },
{ "month": "2026-04-01", "actual": 131 },
{ "month": "2026-05-01", "actual": 142 },
{ "month": "2026-06-01", "actual": 150, "forecast": 150, "low": 150, "high": 150 },
{ "month": "2026-07-01", "forecast": 156, "low": 149, "high": 163 },
{ "month": "2026-08-01", "forecast": 161, "low": 150, "high": 172 },
{ "month": "2026-09-01", "forecast": 167, "low": 152, "high": 182 },
{ "month": "2026-10-01", "forecast": 172, "low": 153, "high": 191 },
{ "month": "2026-11-01", "forecast": 178, "low": 155, "high": 201 },
{ "month": "2026-12-01", "forecast": 184, "low": 157, "high": 211 }
]
},
"charts": [
{
"title": "Improvement by dose, mean and 95% interval",
"note": "Every dose helped more than the placebo; 40 mg did little better than 20 mg, and its interval is wider.",
"how": "Error bars: a rule from y (low) to y2 (high) in the middle of each band, and a point at the mean. A scale that does not start at zero is fine here: the points compare positions, not lengths.",
"spec": {
"data": "trial",
"size": [640, 300],
"scales": { "x": { "type": "band" }, "y": { "type": "linear" } },
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x" },
{ "type": "axis", "scale": "y" }
],
"marks": [
{ "type": "rule", "x": "group", "y": "low", "y2": "high", "strokeWidth": 2 },
{ "type": "point", "x": "group", "y": "mean", "r": 5, "fill": "var(--bc-c0, #3a6fe4)" }
],
"interaction": [
{
"type": "tooltip",
"fields": ["mean", "low", "high"],
"labels": { "mean": "Mean", "low": "Low (95%)", "high": "High (95%)" }
}
]
}
},
{
"title": "Orders, actual and forecast with its 80% range",
"note": "Orders are forecast to reach about 184 in December, most likely between 157 and 211.",
"how": "A confidence band: an area from y (high) to y2 (low), light, under the lines. The forecast starts at the last actual month, where the band is zero wide, so the lines join. Rows without a value leave the mark out there.",
"spec": {
"data": "forecast",
"size": [720, 320],
"scales": { "x": { "type": "time" }, "y": { "type": "linear", "zero": true } },
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x", "format": { "month": "short" } },
{ "type": "axis", "scale": "y" }
],
"marks": [
{ "type": "area", "x": "month", "y": "high", "y2": "low", "fill": "var(--bc-c0, #3a6fe4)", "opacity": 0.18 },
{ "type": "line", "x": "month", "y": "actual", "stroke": "var(--bc-c0, #3a6fe4)" },
{ "type": "line", "x": "month", "y": "forecast", "stroke": "var(--bc-c0, #3a6fe4)", "dash": [5, 4] }
],
"interaction": [
{
"type": "tooltip",
"fields": ["actual", "forecast", "low", "high"],
"formats": { "month": { "month": "long", "year": "numeric" } },
"labels": { "actual": "Actual", "forecast": "Forecast", "low": "Low (80%)", "high": "High (80%)" }
}
]
}
}
]
}
The report the composer makes from it is one standalone file (89.7 KB): open it from disk, mail it, print it.
In a page of your own
The charts above use the dashboard kit (55.5 KB gzipped), the smallest one that has the blocks this example needs:
lib.curve, lib.pointer, lib.ticks, scale.band, scale.linear, scale.time, mark.area, mark.line, 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/dashboard.js"></script>
<script type="application/json" id="bc-data">
{"trial":[{"group":"Placebo","mean":4.1,"low":3.2,"high":5},{"group":"Dose 10 mg","mean":5.6,"low":4.8,"high":6.4},{"group":"Dose 20 mg","mean":6.9,"low":6,"high":7.9},{"group":"Dose 40 mg","mean":7.3,"low":6.1,"high":8.6}],"forecast":[{"month":"2026-01-01","actual":120},{"month":"2026-02-01","actual":128},{"month":"2026-03-01","actual":135},{"month":"2026-04-01","actual":131},{"month":"2026-05-01","actual":142},{"month":"2026-06-01","actual":150,"forecast":150,"low":150,"high":150},{"month":"2026-07-01","forecast":156,"low":149,"high":163},{"month":"2026-08-01","forecast":161,"low":150,"high":172},{"month":"2026-09-01","forecast":167,"low":152,"high":182},{"month":"2026-10-01","forecast":172,"low":153,"high":191},{"month":"2026-11-01","forecast":178,"low":155,"high":201},{"month":"2026-12-01","forecast":184,"low":157,"high":211}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "trial",
"size": [
640,
300
],
"scales": {
"x": {
"type": "band"
},
"y": {
"type": "linear"
}
},
"guides": [
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x"
},
{
"type": "axis",
"scale": "y"
}
],
"marks": [
{
"type": "rule",
"x": "group",
"y": "low",
"y2": "high",
"strokeWidth": 2
},
{
"type": "point",
"x": "group",
"y": "mean",
"r": 5,
"fill": "var(--bc-c0, #3a6fe4)"
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"mean",
"low",
"high"
],
"labels": {
"mean": "Mean",
"low": "Low (95%)",
"high": "High (95%)"
}
}
],
"alt": "Improvement by dose, mean and 95% interval"
}
</script>
<script type="application/json" data-bc-chart>
{
"data": "forecast",
"size": [
720,
320
],
"scales": {
"x": {
"type": "time"
},
"y": {
"type": "linear",
"zero": true
}
},
"guides": [
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x",
"format": {
"month": "short"
}
},
{
"type": "axis",
"scale": "y"
}
],
"marks": [
{
"type": "area",
"x": "month",
"y": "high",
"y2": "low",
"fill": "var(--bc-c0, #3a6fe4)",
"opacity": 0.18
},
{
"type": "line",
"x": "month",
"y": "actual",
"stroke": "var(--bc-c0, #3a6fe4)"
},
{
"type": "line",
"x": "month",
"y": "forecast",
"stroke": "var(--bc-c0, #3a6fe4)",
"dash": [
5,
4
]
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"actual",
"forecast",
"low",
"high"
],
"formats": {
"month": {
"month": "long",
"year": "numeric"
}
},
"labels": {
"actual": "Actual",
"forecast": "Forecast",
"low": "Low (80%)",
"high": "High (80%)"
}
}
],
"alt": "Orders, actual and forecast with its 80% range"
}
</script>