apache / apache/echarts

Tooltip params are not passed properly when the value of one of the series is null, undefined or NaN

Open
#15,821 5 comments 1 reaction 0 assignees View on GitHub
bug en
Dominant language
TypeScript
Stars
67.3k
Forks
19.8k
Avg merge
11d 14h
Merged PRs (30d)
8

Description

### Version
5.2.1

### Reproduction link
[https://codepen.io/htr3n/pen/BaZVPGe](https://codepen.io/htr3n/pen/BaZVPGe)

### Steps to reproduce
1. Create a simple ECharts line graph with two value-based data series
2. Configure ECharts option so that the tooltip is triggered and define a custom tooltip formatter function called `tooltipFormatter`
3. Assign the first series data with `data: [null]`, `data: [undefined]` or `data: [NaN]`
4. Assign the second series data with any valid number, e.g. `data: [0]`
5. Pass the options to ECharts engine.

```javascript
function tooltipFormatter(params) {
console.log(params[1]?.seriesName);
console.log(params[0]?.seriesName);
}

const option = {
tooltip: {
trigger: "axis",
formatter: tooltipFormatter
},
xAxis: {
data: [1]
},
yAxis: {
show: true
},
series: [
{
type: "line",
name: "first",
data: [null]
// data: [NaN]
// data: [undefined]
},
{
type: "line",
name: "second",
data: [0],
}
]
};
```

### What is expected?
The tooltip formatter function `tooltipFormatter` should receive two series and their corresponding values: the first one with `null` (or `undefined`, `NaN`, respectively) and the second with `0`.

### What is actually happening?
The tooltip formatter function `tooltipFormatter` receives only one series which is the second, the first series is not passed in (perhaps due to its value is null, undefined, or NaN).

---
If the first series data is assigned with a valid number such as `data: [1]`, the tooltip formatter receives correctly two series with their corresponding values.

The use case is that, I would want the two series and their values passed into the custom tooltip formatter function regardless so that I can render them according to my application requirements. As the first data series is not passed in if its value is null, undefined, or NaN), the tooltip formatter cannot handle it normally in generic case but has to use some dirty workarounds.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.