diff --git a/src/component/tooltip/seriesFormatTooltip.ts b/src/component/tooltip/seriesFormatTooltip.ts index c6385466ed..cdc3b79795 100644 --- a/src/component/tooltip/seriesFormatTooltip.ts +++ b/src/component/tooltip/seriesFormatTooltip.ts @@ -96,7 +96,8 @@ export function defaultSeriesFormatTooltip(opt: { // be not readable. So we check trim here. noName: !trim(inlineName), value: inlineValue, - valueType: inlineValueType + valueType: inlineValueType, + dataIndex }) ].concat(subBlocks || [] as any) }); diff --git a/src/component/tooltip/tooltipMarkup.ts b/src/component/tooltip/tooltipMarkup.ts index 96031f98cb..a277dad278 100644 --- a/src/component/tooltip/tooltipMarkup.ts +++ b/src/component/tooltip/tooltipMarkup.ts @@ -163,6 +163,7 @@ export interface TooltipMarkupNameValueBlock extends TooltipMarkupBlock { // null/undefined/NaN/''... (displayed as '-'). noName?: boolean; noValue?: boolean; + dataIndex?: number; valueFormatter?: CommonTooltipOption['valueFormatter'] } @@ -332,7 +333,9 @@ function buildNameValue( ? '' : makeValueReadable(name, 'ordinal', useUTC); const valueTypeOption = fragment.valueType; - const readableValueList = noValue ? [] : valueFormatter(fragment.value as OptionDataValue); + const readableValueList = noValue + ? [] + : valueFormatter(fragment.value as OptionDataValue, fragment.dataIndex); const valueAlignRight = !noMarker || !noName; // It little weird if only value next to marker but far from marker. const valueCloseToMarker = !noMarker && noName; diff --git a/src/util/types.ts b/src/util/types.ts index 0057e8fc5e..99ad81c2df 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1265,7 +1265,7 @@ export interface CommonTooltipOption { * * Will be ignored if tooltip.formatter is specified. */ - valueFormatter?: (value: OptionDataValue | OptionDataValue[]) => string + valueFormatter?: (value: OptionDataValue | OptionDataValue[], dataIndex: number) => string /** * Absolution pixel [x, y] array. Or relative percent string [x, y] array. * If trigger is 'item'. position can be set to 'inside' / 'top' / 'left' / 'right' / 'bottom', diff --git a/test/tooltip-valueFormatter.html b/test/tooltip-valueFormatter.html index be4f2270b9..3d48e8e975 100644 --- a/test/tooltip-valueFormatter.html +++ b/test/tooltip-valueFormatter.html @@ -40,7 +40,7 @@
- +
@@ -268,6 +268,43 @@ }); }); + + +