Reference
Custom charts and the theme
The theme values a custom chart gets in the embed, how to follow your brand with them, and how to size and test the chart.
A custom chart is drawn by your own code in a sandboxed frame inside the card. It follows the same brand as the cards around it: the embed sends your theme into the frame as ctx.theme, each time it calls your chart’s render(ctx).
Show custom charts in embeds has the setup and the CSP your page needs.
The optional theme keys below require the plugin release that ships with this docs update ({{PLUGIN_VERSION}} or later).
The theme a chart gets
10 keys are always there. 6 more depend on the embed’s theme or page settings. The unbranded primaryColor keeps the host’s original value for older chart bundles that use it.
| Key | Type | Comes from | Use it for |
|---|---|---|---|
fontFamily | string | The theme | The embed font, with a system sans stack after it, so a font that cannot load never falls to a serif. |
textColor | string | The theme | The chart text color. |
textSecondaryColor | string | The theme | Axis labels and other quiet text. |
background | string | The theme | The page background of the embed. |
surfaceColor | string | The theme | The card background. |
borderColor | string | The theme | Borders and grid lines. |
primaryColor | string | dashboard.ctaColor or the host | The authored color when the active mode has a brand. The host fallback can be bare RGB channels such as 13, 13, 13. Wrap only bare channels in rgb() when you use the value in CSS. |
fontSize | number | The theme | The chart text size in px. |
borderRadius | number | The theme | The corner radius in px. |
palette | string[] | The theme | The chart colors, in order. |
fonts | optional | general.fonts | Your font files. The embed loads them into the frame for you, so fontFamily draws in your font. Do not load src from chart code: the frame blocks font requests. |
derived | optional | The brand color, dashboard.ctaColor | hover, active, selected, subtle, focusRing, onBrand: the brand states the cards use. |
gradient | optional | chart.gradient, when enabled | { startColor, endColor, direction } for a bar fill. |
density | optional | general.density | compact means one step less padding. |
legendPosition | optional | chart.legend.position | Where to draw your legend, if you draw one. |
messages | optional | The custom-messages attribute | Your words for the text keys you set, in the viewer language, for example messages['empty.title']. |
The palette has at most 32 colors. Each string is at most 256 characters.
An optional key can be missing. Always keep a fallback for it.
Follow your brand
Use the MCP tool custom_chart_scaffold to start a chart project. The example below reads the first palette color for fill and the derived brand color for hover. It converts primaryColor to a CSS color for both fallbacks.
function asCssColor(value) {
const channels = value.trim();
return /^\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}$/.test(channels)
? `rgb(${channels})`
: value;
}
globalThis.__dbnCustomChart = {
render(ctx) {
const { theme, container } = ctx;
container.style.fontFamily = theme.fontFamily; // your font, already loaded
container.style.color = theme.textColor;
container.style.background = theme.surfaceColor;
container.style.borderRadius = `${theme.borderRadius}px`;
const primaryColor = asCssColor(theme.primaryColor);
const fill = theme.palette[0] ?? primaryColor;
const hover = theme.derived?.hover ?? primaryColor;
const emptyText = theme.messages?.['empty.title'] ?? 'No data';
// Draw with fill, hover and emptyText.
},
};What styles what
- The card: it is a normal card. Theme fields and the parts
card,card-header,card-title,card-actions(withcard-actions--open) andchartstyle it, as any other card. - Inside the frame: style your markup from
ctx.themeand your chart code. The dashboard’s viewer chart settings stay in the built-in chart editor.
Size the chart
With sizing-mode="auto", call dbnChart.resize(height) from your chart when its content needs a height. The height is whole px, from 80 to 1200. The card takes that height, and the embed sends dbn-height-change with the new total. In a dashboard grid the card keeps its grid height and the chart fills it.
Your font files and the CSP
The embed reads each general.fonts file with a credential-free request and hands the bytes to the chart frame. Allow its host in connect-src for the request and in font-src for the usual font load. For a cross-origin font, configure CORS on the font response for the page that contains the embed, including when that page runs in an iframe. If the file fails to load, the chart uses the system sans font.
Test a custom chart
The chart draws inside two frames. In Playwright, go through both with frameLocator:
const chart = page
.frameLocator('dbn-dashboard iframe') // the frame in the card
.frameLocator('iframe'); // your chart's frame
await expect(chart.locator('.my-chart-bar')).toHaveCount(5);.my-chart-bar is a class in your own chart markup. The card itself takes the part selectors: page.locator('[part~="card-title"]').