blockcharts alpha

Gallery / Trends over time /

Lines by series

Trends of several series, with zoom.

86.8 KB of code · core 29.5 + 16 blocks 57.3

Visits per channel

Web brings the most visits, the app grows fastest. Ctrl + wheel zooms, drag pans, Shift + drag selects a range to zoom to, double-click resets; click a legend item to hide or show a channel.

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: 16 of the 59, 86.8 KB of code, minified, which is 40% of the 215.9 KB that the core and every block weigh together. The report file is 93.4 KB: that code, the data, the styles and the page around them.

BlockWhat it doesShare of the codeKB
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
lib.view
The arithmetic of zooming a scale, even on a log one. Shared by zoom and the zoom buttons.
The arithmetic of zooming a scale, even on a log one. Shared by zoom and the zoom buttons. 0.8
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
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
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.brush
Drag a range to zoom to it.
Drag a range to zoom to it. 3.7
interaction.legend-filter
Click a legend item to hide or show its series.
Click a legend item to hide or show its series. 3.0
interaction.tooltip
The values under the pointer.
The values under the pointer. 10.7
interaction.zoom
Wheel zoom, drag to pan, double-click to reset.
Wheel zoom, drag to pan, double-click to reset. 2.5
renderer.svg
Draws into SVG: sharp, selectable, prints well. The default.
Draws into SVG: sharp, selectable, prints well. The default. 3.9
TotalThe core 29.5 and 16 blocks 57.386.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/lines-by-series.json report.html. Saved as page.json, it composes the same with the skill's own runtime/compose.js.

lines-by-series.json

{
  "title": "Lines by series",
  "data": {
    "traffic": {
      "columns": {
        "date": ["2024-01-01", "2024-02-01", "2024-03-01", "2024-04-01", "2024-05-01", "2024-06-01",
                 "2024-01-01", "2024-02-01", "2024-03-01", "2024-04-01", "2024-05-01", "2024-06-01",
                 "2024-01-01", "2024-02-01", "2024-03-01", "2024-04-01", "2024-05-01", "2024-06-01"],
        "channel": ["web", "web", "web", "web", "web", "web",
                    "app", "app", "app", "app", "app", "app",
                    "email", "email", "email", "email", "email", "email"],
        "visits": [200, 260, 310, 290, 350, 420,
                   120, 150, 210, 260, 280, 330,
                   60, 55, 70, 90, 85, 110]
      }
    }
  },
  "charts": [
    {
      "title": "Visits per channel",
      "note": "Web brings the most visits, the app grows fastest. Ctrl + wheel zooms, drag pans, Shift + drag selects a range to zoom to, double-click resets; click a legend item to hide or show a channel.",
      "spec": {
        "data": "traffic",
        "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" },
          { "type": "legend", "scale": "color", "position": "top" }
        ],
        "marks": [{ "type": "line", "x": "date", "y": "visits", "color": "channel" }],
        "interaction": [{ "type": "zoom", "fit": ["y"] }, { "type": "brush", "fit": ["y"] }, { "type": "legend-filter" }, { "type": "tooltip" }]
      }
    }
  ]
}

The report the composer makes from it is one standalone file (93.4 KB): open it from disk, mail it, print it.

In a page of your own

The charts above use the timeseries kit (52.1 KB gzipped), the smallest one that has the blocks this example needs: lib.curve, lib.pointer, lib.ticks, lib.view, scale.color, scale.linear, scale.time, mark.line, guide.axis, guide.grid, guide.legend, interaction.brush, interaction.legend-filter, interaction.tooltip, interaction.zoom, 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/timeseries.js"></script>

<script type="application/json" id="bc-data">
{"traffic":{"columns":{"date":["2024-01-01","2024-02-01","2024-03-01","2024-04-01","2024-05-01","2024-06-01","2024-01-01","2024-02-01","2024-03-01","2024-04-01","2024-05-01","2024-06-01","2024-01-01","2024-02-01","2024-03-01","2024-04-01","2024-05-01","2024-06-01"],"channel":["web","web","web","web","web","web","app","app","app","app","app","app","email","email","email","email","email","email"],"visits":[200,260,310,290,350,420,120,150,210,260,280,330,60,55,70,90,85,110]}}}
</script>

<script type="application/json" data-bc-chart>
{
  "data": "traffic",
  "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"
    },
    {
      "type": "legend",
      "scale": "color",
      "position": "top"
    }
  ],
  "marks": [
    {
      "type": "line",
      "x": "date",
      "y": "visits",
      "color": "channel"
    }
  ],
  "interaction": [
    {
      "type": "zoom",
      "fit": [
        "y"
      ]
    },
    {
      "type": "brush",
      "fit": [
        "y"
      ]
    },
    {
      "type": "legend-filter"
    },
    {
      "type": "tooltip"
    }
  ],
  "alt": "Visits per channel"
}
</script>