blockcharts alpha

Gallery / Targets and progress /

Bullet chart

Results against their targets, with qualitative ranges.

69.8 KB of code · core 29.5 + 10 blocks 40.3

Results against target

Revenue and new customers beat their targets; satisfaction, at 86% of its target, is the furthest below.

How it is made: Each goal as a share of its target, so different units share one axis. Three rect marks draw the grey bands (poor, fair, good) behind a slim bar of the result (thickness), and mark.rule draws the target as a tick across each band.

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: 10 of the 59, 69.8 KB of code, minified, which is 32% of the 215.9 KB that the core and every block weigh together. The report file is 76.5 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.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
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
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
TotalThe core 29.5 and 10 blocks 40.369.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/bullet.json report.html. Saved as page.json, it composes the same with the skill's own runtime/compose.js.

bullet.json

{
  "title": "Bullet chart",
  "data": {
    "goals": [
      { "metric": "Revenue", "actual": 1.04, "target": 1, "poor": 0.7, "fair": 0.9, "good": 1.2 },
      { "metric": "Gross margin", "actual": 0.93, "target": 1, "poor": 0.7, "fair": 0.9, "good": 1.2 },
      { "metric": "New customers", "actual": 1.12, "target": 1, "poor": 0.7, "fair": 0.9, "good": 1.2 },
      { "metric": "Satisfaction", "actual": 0.86, "target": 1, "poor": 0.7, "fair": 0.9, "good": 1.2 },
      { "metric": "On-time delivery", "actual": 0.97, "target": 1, "poor": 0.7, "fair": 0.9, "good": 1.2 }
    ]
  },
  "charts": [
    {
      "title": "Results against target",
      "note": "Revenue and new customers beat their targets; satisfaction, at 86% of its target, is the furthest below.",
      "how": "Each goal as a share of its target, so different units share one axis. Three rect marks draw the grey bands (poor, fair, good) behind a slim bar of the result (`thickness`), and mark.rule draws the target as a tick across each band.",
      "spec": {
        "data": "goals",
        "size": [720, 300],
        "scales": { "y": { "type": "band", "paddingInner": 0.35 }, "x": { "type": "linear", "domain": [0, 1.2] } },
        "guides": [
          { "type": "grid", "scale": "x" },
          { "type": "axis", "scale": "y" },
          { "type": "axis", "scale": "x", "format": "percent" }
        ],
        "marks": [
          { "type": "rect", "x": "good", "y": "metric", "fill": "var(--bc-grid, #edf0f4)" },
          { "type": "rect", "x": "fair", "y": "metric", "fill": "var(--bc-axis, #cbd2dc)", "opacity": 0.55 },
          { "type": "rect", "x": "poor", "y": "metric", "fill": "var(--bc-axis, #cbd2dc)" },
          { "type": "rect", "x": "actual", "y": "metric", "thickness": 0.36, "radius": 2, "fill": "var(--bc-c0, #3a6fe4)" },
          { "type": "rule", "x": "target", "y": "metric", "thickness": 0.75, "strokeWidth": 2.5, "stroke": "var(--bc-text, #1e293b)" }
        ],
        "interaction": [{ "type": "tooltip", "fields": ["actual", "target"], "formats": { "actual": "percent", "target": "percent" } }]
      }
    }
  ]
}

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

In a page of your own

The charts above use the composition kit (54.9 KB gzipped), the smallest one that has the blocks this example needs: lib.pointer, lib.ticks, scale.band, scale.linear, mark.rect, 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/composition.js"></script>

<script type="application/json" id="bc-data">
{"goals":[{"metric":"Revenue","actual":1.04,"target":1,"poor":0.7,"fair":0.9,"good":1.2},{"metric":"Gross margin","actual":0.93,"target":1,"poor":0.7,"fair":0.9,"good":1.2},{"metric":"New customers","actual":1.12,"target":1,"poor":0.7,"fair":0.9,"good":1.2},{"metric":"Satisfaction","actual":0.86,"target":1,"poor":0.7,"fair":0.9,"good":1.2},{"metric":"On-time delivery","actual":0.97,"target":1,"poor":0.7,"fair":0.9,"good":1.2}]}
</script>

<script type="application/json" data-bc-chart>
{
  "data": "goals",
  "size": [
    720,
    300
  ],
  "scales": {
    "y": {
      "type": "band",
      "paddingInner": 0.35
    },
    "x": {
      "type": "linear",
      "domain": [
        0,
        1.2
      ]
    }
  },
  "guides": [
    {
      "type": "grid",
      "scale": "x"
    },
    {
      "type": "axis",
      "scale": "y"
    },
    {
      "type": "axis",
      "scale": "x",
      "format": "percent"
    }
  ],
  "marks": [
    {
      "type": "rect",
      "x": "good",
      "y": "metric",
      "fill": "var(--bc-grid, #edf0f4)"
    },
    {
      "type": "rect",
      "x": "fair",
      "y": "metric",
      "fill": "var(--bc-axis, #cbd2dc)",
      "opacity": 0.55
    },
    {
      "type": "rect",
      "x": "poor",
      "y": "metric",
      "fill": "var(--bc-axis, #cbd2dc)"
    },
    {
      "type": "rect",
      "x": "actual",
      "y": "metric",
      "thickness": 0.36,
      "radius": 2,
      "fill": "var(--bc-c0, #3a6fe4)"
    },
    {
      "type": "rule",
      "x": "target",
      "y": "metric",
      "thickness": 0.75,
      "strokeWidth": 2.5,
      "stroke": "var(--bc-text, #1e293b)"
    }
  ],
  "interaction": [
    {
      "type": "tooltip",
      "fields": [
        "actual",
        "target"
      ],
      "formats": {
        "actual": "percent",
        "target": "percent"
      }
    }
  ],
  "alt": "Results against target"
}
</script>