A scripted chart is a Scripted Chart widget whose JavaScript script produces an Apache ECharts configuration object. The platform runs the script (in the backend, via the same Goja engine as backend scripts) and renders whatever the script evaluates to.
Note
Scripted charts require the Plus plan (public instance) or the corresponding license flag (cloud). The widget is hidden with a lock and a Subscribe prompt on plans that don’t include it.
Creating a chart#
- Add the Scripted Chart widget to a page or dashboard.
- Fill in its parameters:
- Title — the widget’s heading.
- Group — which group to query. Defaults to
$current(the page’s group); a scripted chart always needs one specific group resolved, soallor an unresolvable group value fails with “Scripted charts require a specific group to be selected”. - JavaScript Code — the script itself (required).
- Re-render when these page settings change — optional. Direct
pageVars.<key>reads in the script are detected automatically and already trigger a re-render when that page variable changes; only list a key here if you read it dynamically (e.g.pageVars[someVariable]), which the automatic detection can’t see.
- Save. The chart re-runs on every render and whenever a watched page variable changes.
The final-expression contract#
Important
The script has no wrapper function and no top-level return. It runs as a plain script, and its last expression statement becomes the chart’s ECharts option. A top-level return is a SyntaxError: Illegal return statement, not a way to produce output.
End the script with either:
- the result of an
echarts.create*helper call, or - a plain option object, optionally built into a variable first and referenced by name as the last line.
// Helper call as the final expression — no `return`, no semicolon-terminated function.
const items = group.queryItems("");
echarts.createPieChart(
Object.entries(itemsByStatus(items)).map(([name, value]) => ({ name, value })),
{ title: "Items by status" }
);
// Building the option in a variable, then ending with it.
const option = {
title: { text: "Items created per month" },
xAxis: { type: "category", data: ["Jan", "Feb", "Mar"] },
yAxis: { type: "value" },
series: [{ type: "line", data: [3, 7, 5] }],
};
option;
The platform validates that the final value is JSON-serializable and looks like a chart config; a script that ends on something else fails with “Script must return a valid ECharts configuration object”.
Available globals#
Scripted charts get the read-only scripting surface — the same shape as an item save-hook script reading data, but with no setters, no fetch, and no secrets:
| Global | Description |
|---|---|
user | The viewer. Data properties only: id, name, email, profilePicture, locale, isActive. |
group | The chart’s resolved group. See below. |
item | The current item, only when the chart widget is placed inside an item’s page layout (item-scoped). undefined on a dashboard or a group-level page. |
pageVars | The current page’s resolved variables, when the chart renders inside a page. See pageVars usage below. |
api | Data-transformation helpers: groupBy, aggregate, filterItems. |
echarts | Chart-config builder helpers: createPieChart, createBarChart, createLineChart, createScatterChart. |
log(...) / console.log(...) | Write to the widget’s log panel (see Errors). Output never becomes part of the chart. |
userId, groupId, instanceId, scriptId, scriptType, itemId | Plain string metadata; scriptType is "chart". itemId is only set when item-scoped. |
isGroupScoped, isInstanceScoped, isItemScoped | Booleans for the current scope. |
group exposes:
| Member | Description |
|---|---|
group.id, group.name | Data properties. |
group.queryItems(query) | Runs a query with RBAC enforced and returns matching items as an array. Throws a TypeError with the parser’s diagnostic on a malformed query — for example queryItems: syntax error at position 5: expected ':' after field 'this' (token: "is"). It does not return an empty array on a bad query. |
group.getMemberById(userId) | One member as a user object, or null. |
group.getMembers() | All members as user objects. |
group.getItemTypes() | [{id, name, description, icon}]. |
group.getStatuses(itemTypeId) | [{id, name, color, icon, enabled}] for that item type’s workflow. icon/enabled come back null when unset. |
group.getFields(itemTypeId) | All fields (default + custom, enabled defaults only) as [{id, name, description, type, icon}]. |
group.getCustomFields(itemTypeId) / group.getDefaultFields(itemTypeId) | The same shape, narrowed to one kind. |
Items returned by queryItems (and item when item-scoped) expose camelCase data — id, title, description, status (a status id, not a display name — resolve it with group.getStatuses), type, groupId, idInGroup, tag, createdBy, assignedTo, isCompleted, and ISO-8601 strings or null for createdAt, updatedAt, dueDate, completedAt — plus getField(fieldId) for any field (default or custom; see Field values) and renderField(fieldId) for its formatted HTML. There are no setters and no save() — see API Reference for the full read-only item surface shared with save-hook scripts.
The echarts helpers#
Each helper takes a data argument and an optional options object, and returns a complete ECharts option. Use them for the common shapes; drop to a raw option object (below) for anything they don’t cover.
echarts.createPieChart(data, options?)#
data is an array of {name, value} (add url per point for drill-down — see below). options.title sets the chart title.
echarts.createPieChart(
[{ name: "open", value: 12 }, { name: "done", value: 30 }],
{ title: "Items by status" }
);
produces:
{
"title": { "text": "Items by status" },
"tooltip": { "trigger": "item", "formatter": "{b}: {c} ({d}%)" },
"legend": { "orient": "vertical", "left": "left" },
"series": [{ "type": "pie", "radius": "50%", "data": [...], "emphasis": { "itemStyle": { "shadowBlur": 10, "shadowOffsetX": 0, "shadowColor": "rgba(0, 0, 0, 0.5)" } } }]
}
echarts.createBarChart(data, options?)#
data is a flat array of numbers (or per-point {value, url} objects). options.categories labels the x-axis; options.title sets the title.
echarts.createBarChart([4, 9, 2], { title: "Open items per person", categories: ["Alice", "Bob", "Cy"] });
produces xAxis: {type:"category", data: options.categories}, yAxis: {type:"value"}, and one series entry of type: "bar".
echarts.createLineChart(data, options?)#
Same shape as bar (data numbers or {value,url}, options.categories, options.title); the series is type: "line" with smooth: true.
echarts.createScatterChart(data, options?)#
data is an array of {value: [x, y]} points (add url per point for drill-down). options.title sets the title; both axes default to type: "value".
echarts.createScatterChart(
[{ value: [Date.parse("2026-01-05"), 3] }, { value: [Date.parse("2026-01-12"), 1] }],
{ title: "Priority vs due date" }
);
Note
None of the helpers accept a colors option. Don’t set explicit colors unless you specifically need to override the theme — the bundled ECharts default palette is designed to look right unset.
Raw ECharts option objects#
For anything the helpers don’t express — mixed series, custom tooltips, dataset, multiple y-axes — end the script with a plain option object using the standard ECharts option API:
const counts = {};
for (const it of group.queryItems("created:>=$today-6m")) {
const month = it.createdAt.slice(0, 7); // items' dates are ISO strings
counts[month] = (counts[month] || 0) + 1;
}
const months = Object.keys(counts).sort();
const option = {
title: { text: "Items created per month" },
tooltip: { trigger: "axis" },
xAxis: { type: "category", data: months },
yAxis: { type: "value" },
series: [{ type: "line", smooth: true, data: months.map((m) => counts[m]) }],
};
option;
Never set width/height in the option — the widget sizes the chart to its tile automatically.
Drill-down links#
Give a data point a url and clicking it navigates there — the standard way to make a chart bucket open the filtered items behind it:
- Pie:
{name, value, url}. Bar/line:{value, url}per point instead of a bare number. Scatter:{value: [x, y], url}. - Build the URL as
"/" + groupId + "/items/" + itemTypeId + "?q=" + encodeURIComponent(query)— use"all"as the item-type segment when the chart spans types. - The query uses the query language — reuse the exact filter that produced the bucket (
"status:" + statusId,"assignedTo:" + userId, combined with" AND "). - URLs must be relative (start with
/); absolute/external URLs are ignored by the renderer. - Only add a
urlwhen the bucket maps cleanly to a query — leave it off synthetic buckets with no query equivalent.
const counts = {};
for (const it of group.queryItems("")) {
const key = it.status || "none";
counts[key] = (counts[key] || 0) + 1;
}
const data = Object.entries(counts).map(([name, value]) => {
const point = { name, value };
if (name !== "none") {
point.url = "/" + groupId + "/items/all?q=" + encodeURIComponent("status:" + name);
}
return point;
});
echarts.createPieChart(data, { title: "Items by status" });
pageVars usage#
When a scripted chart is placed on a page (not a plain dashboard), pageVars gives read access to that page’s resolved variables:
| Access | Behavior |
|---|---|
pageVars.<key> | The variable’s plain JS value directly — a string/number/boolean, a real JS Date for date/datetime variables, or an array of item objects for item-typed variables. undefined for an unset or unknown key (never throws). |
pageVars.has(key) | true/false for whether the key is set. |
pageVars.get(key) | Same value as pageVars.<key>, callable with a dynamic key. |
pageVars.render(key) | The formatted HTML the platform UI would show for that value (user chip, status chip, formatted date, …), or "" if unset. |
pageVars.display(key) | The plain human-readable label version of the same value, or "" if unset. |
pageVars.<key>_expr | For date/datetime variables set via a relative expression (e.g. $today-7d), the expression string. |
pageVars.<key>_range | For date/datetime variables, {from: Date, to: Date} when the variable resolves to a range. |
Note
pageVars is a plain JS object, so Object.keys(pageVars) lists both the page’s variable names and the four accessor names (has, get, render, display) — filter those out if you’re enumerating variable names dynamically.
const status = pageVars.has("statusFilter") ? pageVars.get("statusFilter") : null;
const items = group.queryItems(status ? "status:" + status : "");
echarts.createBarChart([items.length], { title: "Matching items", categories: [status || "all"] });
Direct pageVars.<key> reads (including inside template literals and simple member access) are detected automatically and re-render the chart when that variable changes; only dynamic reads like pageVars[someVariable] need to be listed in the widget’s “Re-render when these page settings change” parameter.
Limits and errors#
Scripted charts run under strict resource limits: 10 second timeout, 50 API calls, 25MB memory. A script that exceeds any of them is cancelled and reported as an error.
Any script failure — a syntax error, a thrown exception, a timeout, an invalid final value — is shown as an inline Script Error box in the chart’s tile, in place of the chart. Every run is also recorded in the chart’s Recent runs, under the code editor in its configuration: status, duration, the error and what the script logged, with the person it ran as — you see your own runs, group administrators see everyone’s. Use log(...) / console.log(...) while developing and check the widget’s log panel.
// queryItems throws — catch it to show a friendlier message instead of the raw parser error.
let items;
try {
items = group.queryItems(pageVars.get("filter") || "");
} catch (e) {
log("bad filter:", e.message);
items = [];
}
echarts.createPieChart([{ name: "matched", value: items.length }], { title: "Results" });
See Limits and Errors for the full picture across every scripting environment, and the Query Language reference for queryItems syntax.
Full examples#
Status pie chart with drill-down#
const counts = {};
for (const it of group.queryItems("")) {
const key = it.status || "none";
counts[key] = (counts[key] || 0) + 1;
}
const data = Object.entries(counts).map(([name, value]) => {
const point = { name, value };
if (name !== "none") {
point.url = "/" + groupId + "/items/all?q=" + encodeURIComponent("status:" + name);
}
return point;
});
echarts.createPieChart(data, { title: "Items by status" });
Workload bar chart#
const counts = {};
for (const it of group.queryItems("completedDate:$empty")) {
const m = it.assignedTo ? group.getMemberById(it.assignedTo) : null;
const name = m ? m.name : "Unassigned";
counts[name] = (counts[name] || 0) + 1;
}
echarts.createBarChart(Object.values(counts), {
title: "Open items per person",
categories: Object.keys(counts),
});
Raw option: items created per month#
const counts = {};
for (const it of group.queryItems("created:>=$today-6m")) {
const month = it.createdAt.slice(0, 7);
counts[month] = (counts[month] || 0) + 1;
}
const months = Object.keys(counts).sort();
const option = {
title: { text: "Items created per month" },
tooltip: { trigger: "axis" },
xAxis: { type: "category", data: months },
yAxis: { type: "value" },
series: [{ type: "line", smooth: true, data: months.map((m) => counts[m]) }],
};
option;
Page-scoped chart reading pageVars and the current item#
// Placed inside an item's page layout: compares the item's own field against
// a page variable set by the viewer.
const threshold = pageVars.has("hoursThreshold") ? Number(pageVars.get("hoursThreshold")) : 8;
const logged = Number(item.getField("loggedHours") || 0);
echarts.createPieChart(
[
{ name: "Logged", value: Math.min(logged, threshold) },
{ name: "Remaining", value: Math.max(threshold - logged, 0) },
],
{ title: item.title + " — time budget" }
);
See also#
- Scripting Overview — all four scripting environments compared.
- Backend Scripts — the writable counterpart (save hooks, automations) sharing the same item/group surface.
- API Reference — the full JavaScript API shared across scripting environments.
- Field Values — what
getField/getFieldreturns for each field type. - Query Language — the syntax
queryItemsaccepts. - Limits and Errors — resource limits and error handling across environments.
- Cookbook — worked examples for every script kind, including charts.