Gallery / Dashboards and reports /
Team dashboard
Several charts on one page.
73.8 KB of code · core 29.5 + 11 blocks 44.3
Tickets opened
Tickets opened peaked at 45 in the week of May 27.
How it is made: Two charts on one page can read the same dataset.
On a page of its own this chart would need 11 blocks, 73.8 KB with the core:
Opened against closed
One dot per week: in three of the six weeks more tickets were opened than closed.
On a page of its own this chart would need 8 blocks, 64.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: 11 of the 59, 73.8 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.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.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.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.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 | |
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 11 blocks 44.3 | 73.8 |
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/dashboard.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
dashboard.json
{
"title": "Team dashboard",
"subtitle": "Support tickets · six weeks from May 6, 2024",
"layout": { "columns": 2 },
"data": {
"tickets": [
{ "week": "2024-05-06", "opened": 34, "closed": 30 },
{ "week": "2024-05-13", "opened": 41, "closed": 38 },
{ "week": "2024-05-20", "opened": 29, "closed": 36 },
{ "week": "2024-05-27", "opened": 45, "closed": 40 },
{ "week": "2024-06-03", "opened": 38, "closed": 44 },
{ "week": "2024-06-10", "opened": 33, "closed": 35 }
]
},
"charts": [
{
"title": "Tickets opened",
"note": "Tickets opened peaked at 45 in the week of May 27.",
"how": "Two charts on one page can read the same dataset.",
"span": 1,
"spec": {
"data": "tickets",
"size": [560, 260],
"scales": { "x": { "type": "time", "padding": 0.03 }, "y": { "type": "linear", "zero": true } },
"guides": [{ "type": "grid", "scale": "y" }, { "type": "axis", "scale": "x" }, { "type": "axis", "scale": "y" }],
"marks": [
{ "type": "line", "x": "week", "y": "opened", "stroke": "var(--bc-c0, #3a6fe4)" },
{ "type": "point", "x": "week", "y": "opened", "r": 3, "fill": "var(--bc-c0, #3a6fe4)" }
],
"interaction": [{ "type": "tooltip", "labels": { "opened": "Opened" } }]
}
},
{
"title": "Opened against closed",
"note": "One dot per week: in three of the six weeks more tickets were opened than closed.",
"span": 1,
"spec": {
"data": "tickets",
"size": [560, 260],
"scales": { "x": { "type": "linear", "padding": 0.1 }, "y": { "type": "linear", "padding": 0.1 } },
"guides": [
{ "type": "grid", "scale": "x" },
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x", "title": "Opened" },
{ "type": "axis", "scale": "y", "title": "Closed" }
],
"marks": [{ "type": "point", "x": "opened", "y": "closed", "r": 5 }],
"interaction": [{ "type": "tooltip", "heading": "week", "fields": ["opened", "closed"], "labels": { "opened": "Opened", "closed": "Closed" }, "formats": { "week": "date" } }]
}
}
]
}
The report the composer makes from it is one standalone file (80.9 KB): open it from disk, mail it, print it.
In a page of your own
The charts above use the basic kit (42.9 KB gzipped), the smallest one that has the blocks this example needs:
lib.curve, lib.pointer, lib.ticks, scale.linear, scale.time, mark.line, mark.point, 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/basic.js"></script>
<script type="application/json" id="bc-data">
{"tickets":[{"week":"2024-05-06","opened":34,"closed":30},{"week":"2024-05-13","opened":41,"closed":38},{"week":"2024-05-20","opened":29,"closed":36},{"week":"2024-05-27","opened":45,"closed":40},{"week":"2024-06-03","opened":38,"closed":44},{"week":"2024-06-10","opened":33,"closed":35}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "tickets",
"size": [
560,
260
],
"scales": {
"x": {
"type": "time",
"padding": 0.03
},
"y": {
"type": "linear",
"zero": true
}
},
"guides": [
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x"
},
{
"type": "axis",
"scale": "y"
}
],
"marks": [
{
"type": "line",
"x": "week",
"y": "opened",
"stroke": "var(--bc-c0, #3a6fe4)"
},
{
"type": "point",
"x": "week",
"y": "opened",
"r": 3,
"fill": "var(--bc-c0, #3a6fe4)"
}
],
"interaction": [
{
"type": "tooltip",
"labels": {
"opened": "Opened"
}
}
],
"alt": "Tickets opened"
}
</script>
<script type="application/json" data-bc-chart>
{
"data": "tickets",
"size": [
560,
260
],
"scales": {
"x": {
"type": "linear",
"padding": 0.1
},
"y": {
"type": "linear",
"padding": 0.1
}
},
"guides": [
{
"type": "grid",
"scale": "x"
},
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x",
"title": "Opened"
},
{
"type": "axis",
"scale": "y",
"title": "Closed"
}
],
"marks": [
{
"type": "point",
"x": "opened",
"y": "closed",
"r": 5
}
],
"interaction": [
{
"type": "tooltip",
"heading": "week",
"fields": [
"opened",
"closed"
],
"labels": {
"opened": "Opened",
"closed": "Closed"
},
"formats": {
"week": "date"
}
}
],
"alt": "Opened against closed"
}
</script>