Skip to content

Conversation

@Mustansir-06
Copy link

This PR adds the series name as a third argument to the valueFormatter function in the tooltip component.

Currently, valueFormatter only receives value and dataIndex. Adding the name (series name) allows users to perform conditional formatting based on the series without having to write a full custom formatter HTML string.

Changes
src/component/tooltip/tooltipMarkup.ts: Updated buildNameValue to pass fragment.name into the valueFormatter call.

src/util/types.ts: Updated the CommonTooltipOption and TooltipValueFormatter types to include the optional name?: string parameter to ensure TypeScript compatibility.

@echarts-bot
Copy link

echarts-bot bot commented Jan 9, 2026

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.

@plainheart
Copy link
Member

valueFormatter is designed for the tooltip of a single series rather than the global tooltip option. See this demo for recommended usage.

@Mustansir-06
Copy link
Author

Thank you for the demo and the feedback @plainheart!

I agree that defining individual formatters works well for a few series. However, the motivation for this PR is to support generic, reusable formatting functions.

If a developer has many series (or a dynamic number of series), they currently have to define a new function for each one to include the series name. By passing the name as a third parameter, a single formatter can be written to handle multiple series dynamically:
// With this PR, one function can handle multiple units dynamically
const myGenericFormatter = (value, index, name) => {
const unitMap = { 'Email': ' unit1', 'Union Ads': ' unit2' };
return value + (unitMap[name] || '');
};
This brings valueFormatter in line with other ECharts formatters that already provide the name context. What are your thoughts on supporting this more dynamic approach?

@Mustansir-06 Mustansir-06 force-pushed the feat/tooltip-formatter-param branch from 2c3009e to 4a9e44b Compare January 9, 2026 13:14
@plainheart
Copy link
Member

plainheart commented Jan 9, 2026

Thanks for your suggestions and work! I don't think it's worth adding a new callback parameter when there's a feasible and less cumbersome solution available, so I'd rather not add it — unless we receive more requests for this feature from developers.

@plainheart
Copy link
Member

plainheart commented Jan 9, 2026

If a developer has many series (or a dynamic number of series), they currently have to define a new function for each one to include the series name

This can be done with a loop. Demo

@Mustansir-06
Copy link
Author

Thank you for the demo, @plainheart!

I see how using a closure within the series.forEach loop effectively captures the series context without needing an additional parameter in the valueFormatter callback. It's a clean way to handle the requirement using the existing API.

I appreciate the time you took to review this and for providing the alternative approach. I'll close this PR for now. Thanks again!

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.

2 participants