echarts icon indicating copy to clipboard operation
echarts copied to clipboard

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

Open htr3n opened this issue 4 years ago • 4 comments
trafficstars

Version

5.2.1

Reproduction link

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.
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.

htr3n avatar Sep 30 '21 23:09 htr3n

Hi! We've received your issue and please be patient to get responded. 🎉 The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that it contains a minimum reproducible demo and necessary images to illustrate. Otherwise, our committers will ask you to do so.

A minimum reproducible demo should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to [email protected]. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe to our mailing list.

Have a nice day! 🍵

echarts-bot[bot] avatar Sep 30 '21 23:09 echarts-bot[bot]

+1 for this issue. We also want to show tooltips when the value is null/undefined.

https://github.com/apache/echarts/assets/9117144/7f88a0f4-764f-4424-b96c-2d494d24101d

ZeRego avatar Mar 09 '22 11:03 ZeRego

This also applies to zero values, right? I don't get those in my tooltip.

cliveportman avatar Mar 30 '23 11:03 cliveportman

I also have the same problem with Heat Map Chart, please advise the solution!

phantrungdien avatar Jun 13 '25 04:06 phantrungdien

+1 for this issue

FedeTommi avatar Aug 13 '25 14:08 FedeTommi