Custom chart
The custom chart is a dashboard card that draws a chart you write. It is for the charts the other dashboard cards do not draw: a box plot, a heat map by hour, a chart with two axes of your own. Every edition has it.
The chart reads only its own queries. It cannot read or write tags, and it cannot send commands.
Two modes
Section titled “Two modes”In the card settings, the Chart code section has a Mode and the Code editor:
| Mode | What you write | Right needed to save |
|---|---|---|
| Script (a function returning the chart option) | the body of a function that receives data and ctx and returns the chart option, a plain object |
dashboards.code and the dashboard edit right |
| Option (JSON with placeholders) | the chart option as JSON, with {{...}} placeholders bound to the card’s queries. No code runs |
the dashboard edit right only |
First add the queries in the Query tab: the chart draws nothing without one (“No query”). The Examples menu offers ready charts built on the card’s own queries: a line with quality, threshold bands, two axes, a box plot of aggregates, a heat map by hour and an option JSON line.
The editor completes data.A to data.H, the field names of the last preview result, ctx.* and the named formatters. Errors are marked at their line.
Script example
Section titled “Script example”A line per tag of query A. Bad values are gaps, and the tooltip shows the quality.
const frames = data.A ? data.A.all : [];const field = (f) => (f.byName.avg ? 'avg' : 'value');return { tooltip: { trigger: 'axis', formatter: '$eax.value' }, legend: { top: 0 }, xAxis: { type: 'time', axisLabel: { formatter: '$eax.time' } }, yAxis: { type: 'value', scale: true }, series: frames.map((f) => ({ name: f.displayName || f.name, type: 'line', showSymbol: false, data: ctx.eax.points(f, field(f)), })),};Option JSON example
Section titled “Option JSON example”The same line from query A’s averages, with no code:
{ "tooltip": { "trigger": "axis", "formatter": "$eax.value" }, "xAxis": { "type": "time", "axisLabel": { "formatter": "$eax.time" } }, "yAxis": { "type": "value", "scale": true, "name": "{{A.unit.avg}}" }, "series": [{ "name": "{{A.name}}", "type": "line", "showSymbol": false, "data": "{{A.points.avg}}" }]}What the code receives
Section titled “What the code receives”data holds the card’s query results:
| Member | What it is |
|---|---|
data.frames |
every result frame |
data.A … data.H |
the first frame of each query; data.A.all lists all its frames (one per tag) |
f.name, f.displayName |
the frame’s name (the tag) and its display name |
f.byName.<field> |
the values of a field (time, value, avg, min, max, quality, simulated…) |
f.units.<field> |
the unit of a field |
f.length, f.meta |
the number of rows, and the frame’s notes |
ctx holds the view:
| Member | What it is |
|---|---|
ctx.range |
{ fromMs, toMs }, the card’s time range |
ctx.variables |
the dashboard variables |
ctx.size |
{ width, height } of the card |
ctx.theme, ctx.lang, ctx.live |
the theme, the language, and whether the dashboard is live |
ctx.fmt.value(v, unit, decimals), ctx.fmt.time(ms), ctx.fmt.duration(ms) |
formatting helpers |
ctx.eax.points(frame, field) |
the points of a series: a Bad value is null (a gap); Uncertain values and values without quality get a triangle symbol and a lower opacity, so they never look Good |
Named formatters. Use "$eax.value", "$eax.time", "$eax.quality" or "$eax.duration" as a formatter. They show unit, decimals and quality the way the other cards do. Any other $eax. name is refused.
Placeholders (option JSON). A string that is exactly one placeholder becomes its value (a list for a field). A placeholder inside a longer string is replaced by its text. A query without data gives an empty list or an empty text. Any other placeholder is refused.
| Placeholder | Value |
|---|---|
{{A.<field>}}, {{A[1].<field>}} |
the values of a field of query A’s first (or second…) frame |
{{A.points.<field>}} |
the points of a series, as ctx.eax.points gives them |
{{A.unit.<field>}} |
the unit of a field |
{{A.name}}, {{A.length}} |
the frame’s name, its number of rows |
{{var.<name>}} |
a dashboard variable |
{{range.from}}, {{range.to}} |
the range, in milliseconds |
The sandbox
Section titled “The sandbox”Every custom chart is drawn in an isolated frame, /static/chart_sandbox.html, served with its own strict content policy. The script runs in a worker inside that frame.
- No network, no cookies, no storage and no access to the operator’s page.
- No tags and no commands. The chart cannot subscribe to a tag, read one by path or write one.
- Data: only the card’s own query results. The server runs those queries with the viewer’s rights: a query that names a tag the viewer may not read is refused as a whole, and the chart gets none of its values. The code never sees a tag the viewer may not read.
- A failed query: a query that failed or was refused never hands the code its previous values. The code gets the frames of its last answer with every value
null, every quality Bad and nothing simulated; times, names, tag paths and units are kept, text values are not, and record rows are left out. The card shows QUERY FAILED, and the query is retried every 30 s (A query that failed or was refused). - Links in the option are ignored. Tooltip HTML is limited to plain formatting (text, bold, italic, lists, small tables); everything else is removed.
- A chart that tries to open another address is stopped and shows “This card tried to open another address and was stopped”.
Limits
Section titled “Limits”| Limit | What happens |
|---|---|
| a script runs longer than 500 ms | the card is marked SLOW |
| a script runs longer than 3 s | it is stopped: “Script stopped: it ran longer than 3 s”. It is tried again on the next refresh, with a growing wait after three stops |
| an option larger than 2 MB, nested more than 20 levels deep, or with more than 200,000 data values | refused: “The option was refused”, with the reason |
| more than 200,000 values in the query results | only the latest 200,000 are given to the code |
| more than 6 custom charts on one page | the others do not draw: “At most 6 custom charts draw on one page”. Their data stays in the CSV export |
A compile or run error shows SCRIPT ERROR with the message, the line and the column.
The CUSTOM mark
Section titled “The CUSTOM mark”Every custom chart shows a CUSTOM mark in its corner. Its tooltip says that the chart is drawn by the dashboard’s own code, not a product card, and names who last changed the code and when (“last changed by user on date and time”). The values and their quality come from the card’s queries.
The server writes who and when. On a save that adds, changes or partly removes a card’s code, the server sets card.meta.codeChangedBy (the signed-in user) and card.meta.codeChangedAt (the time of the save, RFC 3339 UTC). A card whose code is unchanged keeps the stored values, also when it is moved or renamed; a card without code carries none. Values a client sends in these two fields are never kept. A duplicated dashboard keeps the source’s values. Without a stored date the tooltip names the user only; without a user it names no one.
Export. Save as PNG saves the drawing. The CSV is built by the page from the query results it sent in, never by the chart code.
Who may write it
Section titled “Who may write it”- Saving a script needs the
dashboards.coderight (Lead_Engineer and Administrator by default; never the AI co-pilot). Without it, the save is refused with that reason. Card code: the dashboards.code right - Saving option JSON needs only the right to edit dashboards: no code runs.
- Anyone who may open the dashboard sees the chart, with their own read rights.