Skip to content

Function: formatTemplate() ​

ts
function formatTemplate(template, ctx, options?): string;

Experimental

Fill a Plotly-syntax template (see the module docs). Formats: %{v:<d3-format>} for numbers, %{v|<d3-time-format>} for dates; without one, ctx.labels[v] when given, else the raw value.

Parameters ​

ParameterType
templatestring
ctxTemplateContext
optionsTemplateOptions

Returns ​

string

Example ​

ts
formatTemplate('%{x|%b %d}: %{y:.1f} (%{customdata[0]})', {
  values: { x: '2026-03-05', y: 3.14159, customdata: ['a'] },
}); // 'Mar 05: 3.1 (a)'

Released under the MIT License.