p5loom

Charts

A chart is described by its numbers and the names of its fields. The library works out the scales, the ticks and the positions, so a chart is a table and a few elements that read from it, not a list of hand-placed coordinates.

Bars from a tableZero baseline by default
Six months of revenue, drawn as bars on a band x axis and a linear y axis from zero.
{
  "version": 1,
  "seed": 1,
  "canvas": { "width": 640, "height": 400 },
  "data": {
    "sales": [
      { "month": "Jan", "revenue": 120 },
      { "month": "Feb", "revenue": 180 },
      { "month": "Mar", "revenue": 150 }
    ]
  },
  "elements": [
    { "type": "axes", "table": "sales", "x": "month", "y": "revenue" },
    { "type": "bars", "table": "sales", "x": "month", "y": "revenue", "fill": "accent" }
  ]
}
Scalesband, linear, log
ScaleForWhat it does
bandtext categories (the default x of bars)Each category gets its own slot, in the order it first appears.
linearnumbers (the default y)Nice steps (1, 2 or 5 times a power of ten). Starts at zero unless "zero": false.
lognumbers above zero that span powers of tenWhole powers of ten. Set with xScale or yScale.
Visits against time on a log x axis, with points, a path and a legend.
Elements6 chart element types
ElementReadsDraws
axestable, x, yAxis lines, ticks, tick labels, field names as titles, optional grid.
barstable, x, yOne bar per row from the baseline.
pointstable, x, yOne dot per row. r in pixels.
pathtable, x, yA polyline through the rows, in order or sorted by x.
texttext, x, yA label, with size, fill and align.
legenditemsSwatches and labels, one per item, up to 8.

Optional on every table element: frame (where the plot sits, as four fractions of the canvas), xScale, yScale, zero, and fill or stroke as a theme token.

LimitsKept small on purpose

Up to 4 tables, each of up to 1000 rows, with up to 8 fields per row. A field holds a number or a line of text up to 60 characters. A table that does not match its element (a missing field, text on a log axis, a value of zero on a log axis) is refused with the row that caused it.