Skip to content

Add ValueFormat support for axis labels #677

Description

@kuzmadom

Problem

ChartAxisLabels supports numberFormat, dateFormat and dateTimeLabelFormats, but it does not accept the shared ValueFormat API used by data labels and tooltips.

As a result, axis labels cannot use {type: 'custom', formatter} for domain-specific or custom time-zone formatting. Converting a numeric or datetime axis to a category axis changes its scale semantics and is not a general workaround.

Proposal

Add format?: ValueFormat to ChartAxisLabels:

const dateFormatter = new Intl.DateTimeFormat('en-US', {
    timeZone: 'America/New_York',
    month: 'short',
    day: 'numeric',
    hour: '2-digit',
});

xAxis: {
    type: 'datetime',
    labels: {
        format: {
            type: 'custom',
            formatter: ({value}) => dateFormatter.format(Number(value)),
        },
    },
}

When labels.format is set, the raw tick value should be formatted through the existing getFormattedValue utility. It should take precedence over the axis-type-specific options rather than be merged with them. When it is omitted, the current formatting behavior should remain unchanged, including smart datetime formats selected from the tick step.

This reuses the same public contract as series.dataLabels.format and the same formatting pipeline as data labels and tooltips. A separate axis-specific callback API is not needed.

Expected behavior

  • labels.format is available for both X and Y axes. Each ValueFormat variant keeps the existing getFormattedValue semantics for the supplied tick value.
  • A custom formatter receives the raw tick value through the existing {value} argument.
  • The same formatted result is used for label measurement, truncation, overlap handling and both SVG and HTML rendering.
  • Existing numberFormat, dateFormat and dateTimeLabelFormats behavior is preserved when format is omitted.

Additional tick context such as index or first/last state, full custom rendering, per-label styles and event handlers are outside the scope of this issue.

Tests and documentation

Add unit and visual coverage for all format variants, precedence over the existing axis-specific options, both axis directions, and SVG/HTML labels. Add a Storybook example and document labels.format in the Axis Labels and Value Formatting guides.

Related APIs and use cases

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions