Two scales on one chart
Two measures with different units.
82.4 KB of code · core 29.5 + 14 blocks 52.9
Revenue and units sold by month
Revenue doubled from January to August; units sold grew faster, from 3,400 to 8,800.
How it is made: y2 is a second linear scale. A mark chooses it with { field, scale }, and its axis goes to the right with position. Both axes are titled and start at zero, and the legend names the marks: each takes its name as a constant on the color scale.
What the report is made of
The composer reads the JSON below and puts into the page the core and only the blocks its chart uses: 14 of the 59, 82.4 KB of code, minified, which is 38% of the 215.9 KB that the core and every block weigh together. The report file is 89.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.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.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 | |
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.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.legend Legends: categories, a color bar, bubble sizes. | Legends: categories, a color bar, bubble sizes. | 6.0 | |
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.9 | 82.4 |
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/dual-axis.json report.html.
Saved as page.json, it composes the same with the skill's own runtime/compose.js.
dual-axis.json
{
"title": "Two scales on one chart",
"data": {
"monthly": [
{ "month": "2025-01-01", "revenue": 120, "units": 3400 }, { "month": "2025-02-01", "revenue": 150, "units": 3900 },
{ "month": "2025-03-01", "revenue": 130, "units": 5200 }, { "month": "2025-04-01", "revenue": 180, "units": 4800 },
{ "month": "2025-05-01", "revenue": 210, "units": 6100 }, { "month": "2025-06-01", "revenue": 190, "units": 7300 },
{ "month": "2025-07-01", "revenue": 260, "units": 6900 }, { "month": "2025-08-01", "revenue": 240, "units": 8800 }
]
},
"charts": [
{
"title": "Revenue and units sold by month",
"note": "Revenue doubled from January to August; units sold grew faster, from 3,400 to 8,800.",
"how": "y2 is a second linear scale. A mark chooses it with { field, scale }, and its axis goes to the right with position. Both axes are titled and start at zero, and the legend names the marks: each takes its name as a constant on the color scale.",
"spec": {
"data": "monthly",
"size": [720, 320],
"scales": {
"x": { "type": "band", "paddingInner": 0.3 },
"y": { "type": "linear", "zero": true },
"y2": { "type": "linear", "zero": true, "range": "height" },
"color": { "type": "color" }
},
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x", "format": { "month": "short" }, "anchor": "end" },
{ "type": "axis", "scale": "y", "title": "Revenue, $K" },
{ "type": "axis", "scale": "y2", "position": "right", "title": "Units sold", "format": "compact" },
{ "type": "legend", "scale": "color", "position": "top" }
],
"marks": [
{ "type": "rect", "x": "month", "y": "revenue", "color": { "value": "Revenue", "scale": "color" }, "radius": 3 },
{ "type": "line", "x": "month", "y": { "field": "units", "scale": "y2" }, "color": { "value": "Units sold", "scale": "color" } },
{ "type": "point", "x": "month", "y": { "field": "units", "scale": "y2" }, "color": { "value": "Units sold", "scale": "color" }, "r": 4 }
],
"interaction": [
{
"type": "tooltip",
"fields": ["revenue", "units"],
"labels": { "revenue": "Revenue", "units": "Units sold" },
"formats": {
"month": { "month": "long", "year": "numeric" },
"revenue": { "style": "currency", "currency": "USD", "maximumFractionDigits": 0, "suffix": "K" },
"units": "integer"
}
}
]
}
}
]
}
The report the composer makes from it is one standalone file (89.4 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.band, scale.color, scale.linear, mark.line, mark.point, mark.rect, guide.axis, guide.grid, guide.legend, 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">
{"monthly":[{"month":"2025-01-01","revenue":120,"units":3400},{"month":"2025-02-01","revenue":150,"units":3900},{"month":"2025-03-01","revenue":130,"units":5200},{"month":"2025-04-01","revenue":180,"units":4800},{"month":"2025-05-01","revenue":210,"units":6100},{"month":"2025-06-01","revenue":190,"units":7300},{"month":"2025-07-01","revenue":260,"units":6900},{"month":"2025-08-01","revenue":240,"units":8800}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "monthly",
"size": [
720,
320
],
"scales": {
"x": {
"type": "band",
"paddingInner": 0.3
},
"y": {
"type": "linear",
"zero": true
},
"y2": {
"type": "linear",
"zero": true,
"range": "height"
},
"color": {
"type": "color"
}
},
"guides": [
{
"type": "grid",
"scale": "y"
},
{
"type": "axis",
"scale": "x",
"format": {
"month": "short"
},
"anchor": "end"
},
{
"type": "axis",
"scale": "y",
"title": "Revenue, $K"
},
{
"type": "axis",
"scale": "y2",
"position": "right",
"title": "Units sold",
"format": "compact"
},
{
"type": "legend",
"scale": "color",
"position": "top"
}
],
"marks": [
{
"type": "rect",
"x": "month",
"y": "revenue",
"color": {
"value": "Revenue",
"scale": "color"
},
"radius": 3
},
{
"type": "line",
"x": "month",
"y": {
"field": "units",
"scale": "y2"
},
"color": {
"value": "Units sold",
"scale": "color"
}
},
{
"type": "point",
"x": "month",
"y": {
"field": "units",
"scale": "y2"
},
"color": {
"value": "Units sold",
"scale": "color"
},
"r": 4
}
],
"interaction": [
{
"type": "tooltip",
"fields": [
"revenue",
"units"
],
"labels": {
"revenue": "Revenue",
"units": "Units sold"
},
"formats": {
"month": {
"month": "long",
"year": "numeric"
},
"revenue": {
"style": "currency",
"currency": "USD",
"maximumFractionDigits": 0,
"suffix": "K"
},
"units": "integer"
}
}
],
"alt": "Revenue and units sold by month"
}
</script>