在所有输入值为 null 的情况下,在 ECharts 中显示工具提示

Show tooltip in ECharts given all input values null

当图形的所有输入值为 null 时,我在使用 ECharts 折线图显示悬停工具提示时遇到问题。

用例是一个图表,在某些时间点可能有一些 null/undefined 值。对于正常值,图表会像往常一样显示工具提示。每当图表的值为 nullundefined 时,我希望图表仍显示悬停工具提示,但使用自定义格式,例如 'N/A'.

示例代码片段是我从EChart折线图示例中提取的一个简单的EChart配置,并将输入数据更改为null

const container = document.getElementById("main");
const chart = echarts.init(container);

const options = {
  tooltip: {
    trigger: "axis",
    axisPointer: {
      type: "shadow",
      label: {
        show: true,
        overflow: "break"
      }
    }
  },
  xAxis: {
    type: "category",
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: [
    {
      type: "value",
    },
  ],
  series: [
    {
      type: "line",
      data: [null, null, null, null, null, null, null],
    }
  ]
};

chart.setOption(options, true);
#main {
  width: 600px;
  height: 200px;
}
<html>
  <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.2.0/echarts.min.js"></script>
    <div id="main"></div>
  </body>
</html>

遗憾的是,当所有输入值为null(或undefined)时,ECharts 不显示任何工具提示。仅当至少一个输入不是 nullundefined.

时才会显示

如何强制ECharts不显示工具提示,以便显示自定义格式悬停?

具有所有空值的 MWE:https://codepen.io/htr3n/pen/bGRvyJJ

具有至少一个非空值的 MWE:https://codepen.io/htr3n/pen/JjJLQYr

这其实是ECharts 5.2及之前版本的bug。我和 ECharts 团队开了工单,他们会修复并在 v5.3.0 中发布修复。

相关错误票: