Skip to content

feat(legend): support series name in formatter. close #21730 - #21815

Open
Mohitmhatre32 wants to merge 1 commit into
apache:masterfrom
Mohitmhatre32:feat/legend.formatter
Open

Mohitmhatre32 wants to merge 1 commit into
apache:masterfrom
Mohitmhatre32:feat/legend.formatter

Conversation

@Mohitmhatre32

Copy link
Copy Markdown

Brief Information

This pull request is:

  • Bug Fix
  • New Feature
  • Other

What does this PR do?

Adds support for passing the associated series name as the second argument to the legend.formatter callback.

Related Issue: #21730 — Support legend.formatter(name, seriesName)


Details

Before: What was the problem?

Previously, the legend.formatter callback received only the legend item name:

formatter(name)

This made it difficult to identify the associated series, particularly when working with data-item legends such as pie charts.

After: How does it work now?

The callback now receives both the legend item name and its associated series name:

formatter(name, seriesName)

Usage Example:

legend: {
    formatter(name, seriesName) {
        return `${seriesName}: ${name}`;
    }
}

The second argument is optional, ensuring backward compatibility with existing formatter callbacks.

  • Existing callbacks that accept only name continue to work.
  • String-based formatters remain unchanged.
  • The associated series name is now available when needed.

Tests Added

Unit tests have been added to cover:

  • Standard series legends.
  • Pie chart / data-item legends.

Test File: test/ut/spec/component/legend/formatter.test.ts


Validation & Testing

The following checks have been completed successfully:

  • Focused legend formatter tests passed.
  • Full unit test suite passed (196 tests).
  • Type checking passed.
  • ESLint passed.

Documentation

  • This PR does not require documentation changes.
  • Documentation should be updated in a follow-up PR.
  • Documentation changes have been submitted in apache/echarts-doc#xxx.

Miscellaneous

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Merging Options

  • Please squash all commits into a single commit when merging.

Commit Message

feat(legend): support series name in formatter. close #21730

Summary: This enhancement extends the legend.formatter callback with an optional seriesName argument, making it easier to associate legend items with their respective series while maintaining backward compatibility.

@echarts-bot

echarts-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

To reviewers: If this PR is going to be described in the changelog in the future release, please make sure this PR has one of the following labels: PR: doc ready, PR: awaiting doc, PR: doc unchanged

This message is shown because the PR description doesn't contain the document related template.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant