Customization¶
Components take their look from the page around them. A few CSS variables and one JavaScript call cover most needs.
Colors¶
Components read six CSS variables. Define them on :root (or on any parent element) to match your product:
:root {
--bic-bg: #ffffff; /* background of cards, tables and tooltips */
--bic-fg: #1f2937; /* text and axes */
--bic-border: #e5e7eb; /* borders and grid lines */
--bic-primary: #0891b2; /* selection, links, active filter */
--bic-success: #15803d; /* positive change of a score card */
--bic-error: #b91c1c; /* negative change, error messages */
}
If your page uses DaisyUI, there is nothing to do: the variables default to the DaisyUI ones (--color-base-100, --color-base-content, --color-base-300, --color-primary, --color-success, --color-error).
Fonts are inherited from the page.
Chart palette¶
The colors of the series are a list, changed in one line:
window.dashboard.sync({ theme: { palette: ['#0891b2', '#f59e0b', '#10b981', '#ef4444', '#8b5cf6'] } });
Charts already on screen are redrawn. Run this once the connector is loaded, for instance in a <script type="module"> placed after the BI Components scripts.
Light and dark¶
data-theme="dark" on <html> starts the page in dark mode. To switch while the page is open:
window.dashboard.sync({ theme: { mode: 'dark' } }); // or 'light'
Nothing is reloaded and no query is sent again. In a sandboxed frame, the Host does the same with bridge.setState({ theme: { mode: 'dark' } }).
Number formats¶
format (charts, score cards) and formats (tables) accept four names:
| Format | Example (English) |
|---|---|
eur |
€1,234 |
pct |
12.3% (the value is a ratio: 0.123) |
int |
1,234 |
dec |
1,234.50 |
<score-card measure="sum(revenue)" format="eur"></score-card>
<data-table by="country" measures="sum(revenue), count(*)" formats="sum(revenue):eur, count(*):int"></data-table>
In semantic mode the Host returns the format of each measure, so dashboards do not have to set it.
Language and locale¶
- Labels of the components ("No data", "Period", "All"...) are in English. Set
<html lang="fr">for French. - Numbers and dates follow the language of the page (
<html lang>, English when absent). To choose another locale:
window.dashboard.sync({ variables: { locale: 'en-GB' } });
In a sandboxed frame, pass lang to buildSrcdoc and variables: { locale } in the state of the HostBridge.
Custom charts¶
When no component fits, write the chart yourself with ECharts and the same data access as the built-in components. The ECharts theme named app follows the colors above:
<div id="my-chart" style="height: 300px"></div>
<script type="module">
import * as echarts from 'https://cdn.jsdelivr.net/npm/echarts@6.1.0/dist/echarts.esm.min.js';
const chart = echarts.init(document.getElementById('my-chart'), 'app');
async function render() {
const { rows } = await window.dashboard.query({ table: 'orders', metrics: ['sum(revenue)'], dimensions: ['country'] });
chart.setOption({
xAxis: { type: 'category', data: rows.map((row) => row.country) },
yAxis: {},
series: [{ type: 'bar', data: rows.map((row) => row['sum(revenue)']) }],
});
}
chart.on('click', (event) => window.dashboard.filters.toggle('country', event.name)); // filters the rest of the page
window.dashboard.subscribe(render); // filters or period changed
render();
</script>
The script goes after the BI Components scripts. In a sandboxed frame, window.echarts is already there and nothing has to be imported.
Serving the libraries yourself¶
By default the components load ECharts and DuckDB-WASM from the jsDelivr CDN. To serve them from your own domain, redirect their addresses with an import map placed before the BI Components scripts:
<script type="importmap">
{ "imports": { "https://cdn.jsdelivr.net/npm/echarts@6.1.0/dist/echarts.esm.min.js": "/vendor/echarts.esm.min.js" } }
</script>
DuckDB-WASM also downloads its Parquet and JSON readers from extensions.duckdb.org the first time a page reads such a file; CSV files and records pushed by a script need no download.
Sandboxed frames do not need this: their Host embeds the libraries in the frame, which has no network access. See where the iframe gets its libraries.