Bound pens
Bound pens trend data that is not in a historian: SQL tables, LIMS and lab
results, calculations in scripts. Bind props.boundPens to a list of pens:
[ { "id": "lab-ph", "name": "Lab pH", "unit": "pH", "format": "0.00", "color": "#6250d6", "visible": true, "gapAfter": "8h", "data": [ { "t": 1764064800000, "v": 7.21 }, { "t": "2025-11-25T14:00:00+01:00", "v": 7.18, "q": 192 }, { "t": 1764079200000, "v": 7.25, "min": 7.20, "max": 7.31 } ] }, { "id": "line1-mode", "name": "Line 1 mode", "discrete": true, "states": { "0": "Stopped", "1": "Running", "2": { "label": "Cleaning", "color": "#2f6fb0" } }, "data": [[1764064800000, 1], [1764068400000, 2]] }, { "id": "batch-yield", "name": "Batch yield", "unit": "%", "style": "bar", "data": [[1764064800000, 96.4], [1764151200000, 97.1]] }]Pen fields
| Field | Required | Meaning |
|---|---|---|
id |
yes | Stable id. Saved charts and links refer to the pen by it. |
name |
no | Shown in the legend, x-trace and export. Default: the id. |
unit |
no | Engineering unit; pens with the same unit share an axis. |
format |
no | Number format such as #,##0.0, 0.00, 0.0%. |
color |
no | A colour: #rgb, #rgba, #rrggbb, #rrggbbaa, rgb(), rgba() or a colour's name. Default (also for anything else): the next palette colour. |
visible |
no | Default true: on the chart when it opens. false: it waits in the side panel under Bound pens. |
discrete |
no | Draw as a step lane (booleans, states, text). Text values make a pen discrete on their own. With discrete: true, text values stay text as written, so "001" and "1" are different states. |
states |
no | Text per value of a discrete pen, such as {"0": "Stopped", "1": "Running"}. A value is looked up as written first, then as the number it writes ("1.0" is state 1), so "001" and "01" can be named apart. A state can also be an object with a label and a colour: {"2": {"label": "Cleaning", "color": "#2f6fb0"}} (#rgb or #rrggbb). |
style |
no | How a numeric pen is drawn when the chart has not set it: line (default), area, bar or points. A chart's Show as overrides it, Line and Step line too. |
start, end |
no | For a pen that follows the visible range: the range its query asked for (output.dataStart and output.end as it read them), not the times of its first and last row. Epoch milliseconds, ISO 8601 text or dates, whatever timeUnit says. Both or neither; null counts as given (see Following the visible range). |
timeUnit |
no | The unit of numeric row times: ms (default) for epoch milliseconds, s for epoch seconds. |
gapAfter |
no | How often the pen has a row at least: milliseconds, or text such as "90s", "15m", "8h", "1d". Rows further apart than that have a gap between them: the line breaks gapAfter after the first, and the x-trace says nothing is stored there. An export writes the rows as bound, without those gaps. Without it, rows far apart are a value holding (or a line between samples). |
limits |
no | Its limits, shown until the chart switches them off: {"lolo": 6.8, "lo": 6.9, "hi": 7.3, "hihi": 7.4, "draw": "both"}. The levels in any case and also as high, low, HH, LL; draw is line (default), band or both. See Limits. |
data |
yes | The rows, as below. |
Rows. data can be:
- a list of objects. The time key is
t,ts,time,timestamp,t_stampordate; the value key isv,value,valory(any case);qorqualityis optional;minandmaxare optional and draw a band; - a list of
[time, value]or[time, value, quality]pairs; - a dataset (a query binding's default return format). Perspective hands it to
the component as a list of objects, one per row keyed by its column names, so
the names above apply. Columns of other names (
sampled_at,ntu) are taken in their order: the first is the time and the next the value. A script's dictionaries keep no order, so give their keys the names above.
Times are epoch milliseconds (epoch seconds with "timeUnit": "s"), ISO 8601 text
or dates. The unit of a number is never guessed. ISO 8601 text is a date
(2025-11-25, midnight UTC) or a date and time (2025-11-25T14:00,
2025-11-25T14:00:00.250+01:00, a space for the T as SQL writes it, an offset
in hours alone as PostgreSQL writes a timestamptz as text, 2025-11-25 14:00:00+01;
without Z or an offset, the browser's time zone); other text (-5, Batch 12,
Nov 25 2025) is no time. Rows are
sorted by time; rows without a readable time (also a dataset row that is not a
list) are skipped and counted in the side panel. Quality is an Ignition quality code, read as Ignition reads it: a
full code (192 Good, 1073742080 Uncertain, -2147483136 Bad, as
qualityCode.getCode() gives them) or a subcode (0 to 255 good, 256 to 511
uncertain, 512 and up bad), also as text ("192"), a name (Good...,
Uncertain..., anything else bad), or true/false (also as text). Bad rows are gaps with a red band. Ignition 7 data
integrity numbers (where only 192 was good) read differently: map them to
true/false or a name in the query.
Following the visible range. The component writes the visible range to
props.output.start and props.output.end, and props.output.dataStart: the
earliest time it needs, which reaches back to the start of the earliest
comparison while one is on. Bind your query to dataStart and end so a bound pen reads
what is on screen and what the comparison shows. A live chart updates output
when it has moved a twentieth of its span, not every second.
Give a pen that follows the range start and end fields (epoch
milliseconds or dates): the range its rows cover. The chart then knows when a
binding has not caught up: an export writes output with the exact range it
exports and waits a few seconds until they are exactly that range, dataStart to
end, to the millisecond (so pass output.dataStart and output.end on as
read: the rows of an earlier, wider read, before a zoom in, are not taken), and
otherwise says so instead of writing old rows; the chart on screen allows a
second either side; and a comparison only uses rows of the earlier period. A pen
that has neither field is taken as complete. Give both or neither: a pen with
only one of them, either or both null (a binding that clears them while its
query runs still holds the rows of the one before), an end before its start, or
a value that is no time shows none of its rows and says why, and an export
waits for it and then is refused with why.
Include the last row before dataStart as well (and, for a line, the first
after end): the chart starts a step or a line at the left edge from it.
Without it a sparse pen (lab samples hours apart) shows nothing at the left
edge until its first row in view, and a period comparison, which reads further
back, would show a value there that the chart without it does not.
Example: script transform
Section titled “Example: script transform”A property binding on this.props.output with a script transform (from the
sample project):
def transform(self, value, quality, timestamp): start = value.get("dataStart") or system.date.toMillis(system.date.addDays(system.date.now(), -30)) end = value.get("end") or system.date.toMillis(system.date.now()) a, b = system.date.fromMillis(start), system.date.fromMillis(end) # The rows in the range, with the last one before it and the first one after it. rows = list(system.db.runPrepQuery( "(SELECT sampled_at, value, approved FROM lab_samples " " WHERE parameter = 'pH' AND sampled_at < ? ORDER BY sampled_at DESC LIMIT 1) " "UNION ALL (SELECT sampled_at, value, approved FROM lab_samples " " WHERE parameter = 'pH' AND sampled_at BETWEEN ? AND ?) " "UNION ALL (SELECT sampled_at, value, approved FROM lab_samples " " WHERE parameter = 'pH' AND sampled_at > ? ORDER BY sampled_at LIMIT 1) " "ORDER BY sampled_at", [a, a, b, b], "powerchart")) return [{ "id": "lab-ph", "name": "Lab pH", "unit": "pH", "format": "0.00", "start": start, "end": end, # The pH spec (Lo and Hi) and action limits (LoLo and HiHi). "limits": {"lolo": 6.8, "lo": 6.9, "hi": 7.3, "hihi": 7.4, "draw": "both"}, "data": [{"t": system.date.toMillis(r["sampled_at"]), "v": r["value"], "q": 192 if r["approved"] else "Uncertain"} for r in rows], }]Example: named query
Section titled “Example: named query”Set the pen's fields in the view and bind only its data. With a named query
Lab/Samples (parameters start and end, DateTime):
(SELECT sampled_at AS t, value AS v FROM lab_samples WHERE parameter = 'pH' AND sampled_at < :start ORDER BY sampled_at DESC LIMIT 1)UNION ALL(SELECT sampled_at AS t, value AS v FROM lab_samples WHERE parameter = 'pH' AND sampled_at BETWEEN :start AND :end)UNION ALL(SELECT sampled_at AS t, value AS v FROM lab_samples WHERE parameter = 'pH' AND sampled_at > :end ORDER BY sampled_at LIMIT 1)ORDER BY t(PostgreSQL and MySQL syntax; on SQL Server use TOP 1.)
- Set
props.boundPensto[{"id": "lab-ph", "name": "Lab pH", "unit": "pH"}]. - Add a query binding on
props.boundPens[0].data: the named query, return format JSON (or Dataset), parameterstoDate({this.props.output.dataStart})andtoDate({this.props.output.end}).
A query binding on data alone cannot say which range its rows cover, so leave
start and end out there; use the script transform above (which returns
both with the rows) when exports and comparisons must know.
Copied from the section "Bound pens" of the README when the site is built. Source: README.md.