One script tag
A kit is the core and a set of blocks in a single file. Add one script, describe the chart in JSON in the page, and it is drawn when the page loads.
A chart from a kit
Charts mount themselves on DOMContentLoaded: every script[data-bc-chart] gets a div.bc-chart right after it. Data goes into script#bc-data by name, so several charts can share it.
Click a legend item to hide a series. From the CDN the first line is <script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.5/release/kits/timeseries.js"></script>, pinned to a version; from your own site, the path you serve the file at.
HTML
<script src="/release/kits/timeseries.js"></script>
<script type="application/json" id="bc-data">
{"visits":[{"month":"2024-01-01","channel":"web","visits":200},{"month":"2024-02-01","channel":"web","visits":260},{"month":"2024-03-01","channel":"web","visits":310},{"month":"2024-04-01","channel":"web","visits":290},{"month":"2024-05-01","channel":"web","visits":350},{"month":"2024-06-01","channel":"web","visits":420},{"month":"2024-01-01","channel":"app","visits":120},{"month":"2024-02-01","channel":"app","visits":150},{"month":"2024-03-01","channel":"app","visits":210},{"month":"2024-04-01","channel":"app","visits":260},{"month":"2024-05-01","channel":"app","visits":280},{"month":"2024-06-01","channel":"app","visits":330}]}
</script>
<script type="application/json" data-bc-chart>
{
"data": "visits",
"size": [720, 300],
"scales": {
"x": { "type": "time" },
"y": { "type": "linear", "zero": true },
"color": { "type": "color" }
},
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x" },
{ "type": "axis", "scale": "y", "title": "Visits" },
{ "type": "legend", "scale": "color", "position": "top" }
],
"marks": [{ "type": "line", "x": "month", "y": "visits", "color": "channel" }],
"interaction": [{ "type": "tooltip" }, { "type": "legend-filter" }]
}
</script> Which kit
Kits are lists of blocks in kits.json; the guide has the sizes. basic is bars, lines, points, areas and a tooltip. timeseries adds zoom, brush, filtering by legend and decimation. composition is pie, heatmap, histogram and stacks. full has everything. A kit built for exactly one page is one command: node scripts/build-dist.js --page page.json=report.