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-EUR 10K-EUR 10K-EUR 5K-EUR 5KEUR 0EUR 0EUR 5KEUR 5KEUR 10KEUR 10KPeriod 1Period 1Period 2Period 2Period 3Period 3Period 4Period 4Period 5Period 5Period 6Period 6EUR 4.2KEUR 4.2KEUR 5.3KEUR 5.3KEUR 6.8KEUR 6.8KEUR 4.8KEUR 4.8K-EUR 5.1K-EUR 5.1KEUR 5.9KEUR 5.9KMean: EUR 4,081.82Mean: EUR 4,081.82

Revenue by period · custom

Original data
SeriesCategory XidxyVisible
Series 1Period 1series-0-0period-04200Yes
Series 1Period 2series-0-1period-16100Yes
Series 1Period 3series-0-2period-25300Yes
Series 1Period 4series-0-3period-3Missing measurementYes
Series 1Period 5series-0-4period-47200Yes
Series 1Period 6series-0-5period-56800Yes
Series 2Period 1series-1-0period-03300Yes
Series 2Period 2series-1-1period-14800Yes
Series 2Period 3series-1-2period-20Yes
Series 2Period 4series-1-3period-3-5100Yes
Series 2Period 5series-1-4period-46400Yes
Series 2Period 6series-1-5period-55900Yes

Last selected point: —

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.

data + options
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.

custom-chart.ts
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.