Customization
Customize the chart with the Web renderer’s content ports. The text is also used on the server, for accessibility and for export.
Try customization
Change formatting and explore the chart to see all five customization slots in use. The code below reflects the applied settings.
Configure a real chart. The code below shows input data and options, including responsive rules.
Current mean: EUR 4,081.82
Revenue by period · custom
| Series | Category X | id | x | y | Visible |
|---|---|---|---|---|---|
| Series 1 | Period 1 | series-0-0 | period-0 | 4200 | Yes |
| Series 1 | Period 2 | series-0-1 | period-1 | 6100 | Yes |
| Series 1 | Period 3 | series-0-2 | period-2 | 5300 | Yes |
| Series 1 | Period 4 | series-0-3 | period-3 | Missing measurement | Yes |
| Series 1 | Period 5 | series-0-4 | period-4 | 7200 | Yes |
| Series 1 | Period 6 | series-0-5 | period-5 | 6800 | Yes |
| Series 2 | Period 1 | series-1-0 | period-0 | 3300 | Yes |
| Series 2 | Period 2 | series-1-1 | period-1 | 4800 | Yes |
| Series 2 | Period 3 | series-1-2 | period-2 | 0 | Yes |
| Series 2 | Period 4 | series-1-3 | period-3 | -5100 | Yes |
| Series 2 | Period 5 | series-1-4 | period-4 | 6400 | Yes |
| Series 2 | Period 6 | series-1-5 | period-5 | 5900 | Yes |
The mean includes every valid value of the chosen series, including zero; missing values are omitted. Visible mode recalculates when hiding series. It updates with the data and does not depend on zoom. An out-of-domain target is not drawn. Currency and unit formatting does not convert values.
const data = {
"type": "column",
"axes": {
"x": {
"type": "category",
"values": [
{
"id": "period-0",
"label": "Period 1"
},
{
"id": "period-1",
"label": "Period 2"
},
{
"id": "period-2",
"label": "Period 3"
},
{
"id": "period-3",
"label": "Period 4"
},
{
"id": "period-4",
"label": "Period 5"
},
{
"id": "period-5",
"label": "Period 6"
}
]
},
"y": {
"type": "linear"
}
},
"series": [
{
"id": "series-0",
"name": "Series 1",
"data": [
{
"id": "series-0-0",
"x": "period-0",
"y": 4200
},
{
"id": "series-0-1",
"x": "period-1",
"y": 6100
},
{
"id": "series-0-2",
"x": "period-2",
"y": 5300
},
{
"id": "series-0-3",
"x": "period-3",
"y": null
},
{
"id": "series-0-4",
"x": "period-4",
"y": 7200
},
{
"id": "series-0-5",
"x": "period-5",
"y": 6800
}
]
},
{
"id": "series-1",
"name": "Series 2",
"data": [
{
"id": "series-1-0",
"x": "period-0",
"y": 3300
},
{
"id": "series-1-1",
"x": "period-1",
"y": 4800
},
{
"id": "series-1-2",
"x": "period-2",
"y": 0
},
{
"id": "series-1-3",
"x": "period-3",
"y": -5100
},
{
"id": "series-1-4",
"x": "period-4",
"y": 6400
},
{
"id": "series-1-5",
"x": "period-5",
"y": 5900
}
]
}
]
};
const options = {
"title": "Revenue by period",
"locale": "en",
"theme": "light",
"height": 380,
"animation": {
"enabled": false
},
"formatting": {
"locale": "en-US",
"number": {
"minimumFractionDigits": 2,
"maximumFractionDigits": 2,
"style": "currency",
"currency": "EUR",
"currencyDisplay": "code",
"currencySign": "standard"
}
},
"appearance": {
"colors": [
"#2c6ed5",
"#698e37"
],
"markers": true,
"dataLabels": true,
"labelLimit": 8
},
"hiddenSeriesIds": [],
"legend": {
"position": "bottom"
},
"tooltip": {
"crosshair": true,
"content": "shared"
},
"references": [
{
"id": "comparison",
"axis": "y",
"value": 4081.818181818182
}
],
"referenceLabels": [
{
"id": "comparison",
"text": "Mean: EUR 4,081.82"
}
],
"referenceStyles": [
{
"id": "comparison",
"color": "#875310",
"dash": "dashed",
"width": 1.5
}
],
"responsive": [
{
"maxWidth": 430,
"options": {
"height": 320,
"tooltip": {
"placement": "docked"
},
"appearance": {
"dataLabels": false
},
"axes": {
"y": {
"numberFormat": {
"minimumFractionDigits": 0,
"maximumFractionDigits": 0,
"style": "currency",
"currency": "EUR",
"currencyDisplay": "narrowSymbol",
"currencySign": "standard",
"notation": "compact"
}
}
}
}
}
]
};Copy the full file to reproduce the data, options and customization you see now. Choose Lines on this page to try a UTC date axis.
import {createChart, type ChartData} from '@neural-charts/web';
import {ChartContentSlotName, type ChartContentPorts, type ChartOptions} from '@neural-charts/web';
export function createContent(options: ChartOptions, timeAxis: boolean, browserTemplates = false): ChartContentPorts {
const region = options.formatting?.locale ?? options.locale ?? 'en';
const numberOptions = options.formatting?.number;
const number = new Intl.NumberFormat(region, numberOptions);
const compact = new Intl.NumberFormat(region, {
...numberOptions,
notation: 'compact',
minimumFractionDigits: 0,
maximumFractionDigits: 1,
});
const date = new Intl.DateTimeFormat(region, {day: 'numeric', month: 'short', timeZone: 'UTC'});
const text = {
[ChartContentSlotName.Title]: {text: context => context.defaultText + (context.locale === 'es' ? ' · personalizado' : ' · custom')},
[ChartContentSlotName.Tooltip]: {text: context => {
const value = context.observation.xValue;
const heading = timeAxis && value !== undefined ? date.format(value) : context.observation.label;
const title = context.locale === 'es' ? 'Detalle personalizado' : 'Custom detail';
const missing = context.locale === 'es' ? 'Medición ausente' : 'Missing measurement';
const rows = context.rows?.map(row => row.name + ': ' + (row.point ? number.format(row.point.value) : missing))
?? context.points.map(point => point.seriesName + ': ' + number.format(point.value));
return [title + ' · ' + heading, ...rows].join('\n');
}},
[ChartContentSlotName.Legend]: {text: context => context.name + (context.visible ? '' : context.locale === 'es' ? ' · oculta' : ' · hidden')},
[ChartContentSlotName.AxisLabel]: {text: context => {
const {tick, axis, defaultText} = context;
if (typeof tick.value !== 'number') return defaultText;
if (axis === 'x' && tick.type === 'time') return date.format(tick.value);
if (axis === 'y' && tick.type === 'number') return compact.format(tick.value);
return defaultText;
}},
[ChartContentSlotName.DataLabel]: {text: context => {
const value = context.observation?.value;
if (value === undefined) return context.defaultText;
const label = compact.format(value);
return options.appearance?.points ? (context.index + 1) + ' · ' + label : label;
}},
} satisfies ChartContentPorts;
if (!browserTemplates) return text;
const html = (tag: 'strong' | 'em', attribute: string) => (host: HTMLElement, context: {readonly text: string}) => {
const node = host.ownerDocument.createElement(tag);
node.setAttribute(attribute, '');
node.textContent = context.text;
host.append(node);
return () => node.remove();
};
const svg = (attribute: string) => (host: SVGTextElement, context: {readonly text: string}) => {
const node = host.ownerDocument.createElementNS('http://www.w3.org/2000/svg', 'tspan');
node.setAttribute(attribute, '');
node.setAttribute('font-weight', '600');
node.textContent = context.text;
host.append(node);
return () => node.remove();
};
return {
[ChartContentSlotName.Title]: {...text[ChartContentSlotName.Title], render: html('strong', 'data-custom-title')},
[ChartContentSlotName.Tooltip]: {...text[ChartContentSlotName.Tooltip], render: html('strong', 'data-custom-tooltip')},
[ChartContentSlotName.Legend]: {...text[ChartContentSlotName.Legend], render: html('em', 'data-custom-legend')},
[ChartContentSlotName.AxisLabel]: {...text[ChartContentSlotName.AxisLabel], render: svg('data-custom-axis')},
[ChartContentSlotName.DataLabel]: {...text[ChartContentSlotName.DataLabel], render: svg('data-custom-label')},
};
}
// Add <div id="chart"></div> in the HTML for this module.
const host = document.getElementById('chart');
if (!host) throw new Error('Missing #chart');
const data: ChartData = {
"type": "column",
"axes": {
"x": {
"type": "category",
"values": [
{
"id": "period-0",
"label": "Period 1"
},
{
"id": "period-1",
"label": "Period 2"
},
{
"id": "period-2",
"label": "Period 3"
},
{
"id": "period-3",
"label": "Period 4"
},
{
"id": "period-4",
"label": "Period 5"
},
{
"id": "period-5",
"label": "Period 6"
}
]
},
"y": {
"type": "linear"
}
},
"series": [
{
"id": "series-0",
"name": "Series 1",
"data": [
{
"id": "series-0-0",
"x": "period-0",
"y": 4200
},
{
"id": "series-0-1",
"x": "period-1",
"y": 6100
},
{
"id": "series-0-2",
"x": "period-2",
"y": 5300
},
{
"id": "series-0-3",
"x": "period-3",
"y": null
},
{
"id": "series-0-4",
"x": "period-4",
"y": 7200
},
{
"id": "series-0-5",
"x": "period-5",
"y": 6800
}
]
},
{
"id": "series-1",
"name": "Series 2",
"data": [
{
"id": "series-1-0",
"x": "period-0",
"y": 3300
},
{
"id": "series-1-1",
"x": "period-1",
"y": 4800
},
{
"id": "series-1-2",
"x": "period-2",
"y": 0
},
{
"id": "series-1-3",
"x": "period-3",
"y": -5100
},
{
"id": "series-1-4",
"x": "period-4",
"y": 6400
},
{
"id": "series-1-5",
"x": "period-5",
"y": 5900
}
]
}
]
};
const options: ChartOptions = {
"title": "Revenue by period",
"locale": "en",
"theme": "light",
"height": 380,
"animation": {
"enabled": false
},
"formatting": {
"locale": "en-US",
"number": {
"minimumFractionDigits": 2,
"maximumFractionDigits": 2,
"style": "currency",
"currency": "EUR",
"currencyDisplay": "code",
"currencySign": "standard"
}
},
"appearance": {
"colors": [
"#2c6ed5",
"#698e37"
],
"markers": true,
"dataLabels": true,
"labelLimit": 8
},
"hiddenSeriesIds": [],
"legend": {
"position": "bottom"
},
"tooltip": {
"crosshair": true,
"content": "shared"
},
"references": [
{
"id": "comparison",
"axis": "y",
"value": 4081.818181818182
}
],
"referenceLabels": [
{
"id": "comparison",
"text": "Mean: EUR 4,081.82"
}
],
"referenceStyles": [
{
"id": "comparison",
"color": "#875310",
"dash": "dashed",
"width": 1.5
}
],
"responsive": [
{
"maxWidth": 430,
"options": {
"height": 320,
"tooltip": {
"placement": "docked"
},
"appearance": {
"dataLabels": false
},
"axes": {
"y": {
"numberFormat": {
"minimumFractionDigits": 0,
"maximumFractionDigits": 0,
"style": "currency",
"currency": "EUR",
"currencyDisplay": "narrowSymbol",
"currencySign": "standard",
"notation": "compact"
}
}
}
}
}
]
};
const result = createChart(host, data, options, {
instanceId: 'custom',
content: createContent(options, false, true),
});
if (result.status !== 'ok') throw new Error(result.diagnostic.message);
export const chart = result.value;
// Call chart.destroy() when the host is removed.Title
Add visual hierarchy to the title. Keep its portable text so the accessible name and exported title agree.
Tooltip
Present the active observation. Its context contains the datum and may include series at the same position in shared mode.
Legend
Customize the visible series name. The chart owns the buttons, visibility state and keyboard navigation.
Axis labels
The context identifies the X, Y and secondary axes and provides the original tick value. Use a tspan element for SVG presentation.
Data labels
Show the value alongside its mark. Enable appearance.dataLabels on a supported chart. The default text already uses the applied format.