Loading the documentation…

Custom visual SDK

An HTML + JS custom visual draws its tile with the uni global: the rows the report sends, selection, saved state, the report's theme, assets, libraries and the outside content the sandbox allows. This page is the developer reference for that global and the platform limits around it. For the editor around your code, see The custom visual Studio; for the tier that runs no JavaScript, Custom visual templates.

What the uni global carries

The groups behind the global:

GroupMembersUse it for
uni.datastatus, fields, dimensions, measures, rows, total, loaded, hasMore, isEmpty, error, field, role, value, text, number, sum, avg, min, max, count, groupBy, sortBy, requestMoreReading what the tile received
uni.themeappearance, tokens, chartColors, color, hex, chart, series, ramp, diverging, echarts, chartjs, vegaConfig, plotColours and chart-library themes
uni.formatvalue, number, percent, abbrev, dateFormatting values yourself
uni.selectionown, origin, isSelectedYour marks and the highlight state
uni.slicerenabled, field, values, set, clear, autoPickThe slicer role
uni.stateget, set, resetThe viewer's saved state
uni.exportHooksonSnapshot, onNative, pageCount, setPageThe export picture
uni.assetsurl, bytes, list, has, jsonThe files attached to the visual
uni.renderLifecyclestarted, finished, failedLong paints

Paint, react and clean up

js
uni.render((ctx) => {
  const label = ctx.data.isEmpty ? 'No rows' : `${ctx.data.count()} rows`;
  uni.text(ctx.root, label);
});

Read the rows and the fields

Select, and serve as a slicer

State, formatting and options

Helpers, tooltips and logs

Theme and colour

Assets, images, embeds and links

Libraries and icons

The export picture

Platform limits

WhatLimit
Source filesvisual.html 96 KB, visual.css 64 KB, visual.js 128 KB, 256 KB together
Template96 KB, 20,000 rendered nodes, expressions nesting up to 32 deep (see Custom visual templates)
Viewer state16 KB
Slicer set1,000 values
Embeds32 per visual
Native export400 elements; 2,000 characters of text; a table 30 columns by 100 rows; a chart 200 categories and 20 series

Checks and diagnostics

Questions, answered

Is there an SDK for the template tier?

No. A Template visual runs no author JavaScript, so uni does not exist in it; read rows, groups and options through interpolations and the directives described in Custom visual templates. Switch to HTML + JS when you need libraries or the full uni global.

How do I read the field bound to a data role?

uni.data.role('roleId', index) returns the field bound to that role, and the index picks among several fields in the same role. Bound fields also carry their role id in field.role, and uni.data.fields lists them all.

How do I know why my visual is being painted?

The paint's context carries reason: mount for the first paint, swap when the code is replaced, or the change that triggered it (data, size, theme, selection, filters, options, state, reset or mode). Use it to skip work a paint does not need.

What should my visual draw when the data is loading or denied?

Read uni.data.status: draw a loading state for loading and refreshing, the tile's empty or error state for error, and an empty state for rlsDenied, where row-level security withholds the rows. An empty result is isEmpty.

Why is uni.select doing nothing?

Either selection is switched off for the tile, which warns uni.select: selection is disabled for this visual (interactions.select = false), or the tile is in the slicer role, where uni.select is disabled and uni.slicer.set replaces it. Check uni.capabilities.select and uni.capabilities.slicer.

Where do messages I write from the visual appear?

In the Studio's Diagnostics. uni.log(level, ...args) writes a console entry (debug and info read as log entries, warn and error keep their level), and plain console calls from your code are collected the same way.

How do I paint differently for light and dark?

Read uni.theme.appearance (light or dark) and draw with the tokens: the report's tokens are applied to the visual as CSS variables, with a --uni- mirror in hsl(...) form and a light or dark class on the frame. A theme switch runs the paint again, so a repaint picks the new values up.

Why does a colour disappear when I write var(--primary)?

Theme names are colour channels, not colours: var(--primary) holds channel numbers, so the browser drops the declaration. Write hsl(var(--primary)) or var(--uni-primary).

Why does uni.image reject an image?

The rejection carries a code: host-not-allowed, not-https, not-an-image, too-large or upstream. A refusal by host, scheme, type or size is remembered, so a repeat fails the same way; an upstream failure is retried. Ask an administrator to allow the host, or load from one that is already allowed; see Sandbox, network and the allowlist.

Is uni.unsafeHtml actually unsafe?

No. It is the only entry that accepts raw markup, and the markup runs through the sandbox's sanitiser first; uni.html escapes every interpolated value. Keep row values in text positions either way, because escaping does not make a value safe inside href, src or style.

How can my visual provide its own export image?

With uni.exportHooks.onSnapshot(handler): the handler is asked for a canvas, an SVG or a blob when the report is exported or printed. onNative provides native pieces instead, and pageCount with setPage handle a visual that spans several pages.

Why does changing the libraries reload my visual?

The declared libraries install once per frame, so changing the set replaces the frame with one that carries the new set. Only the twelve libraries listed above can be declared; anything the visual does not declare is refused, and the refusal names it.