echarts tooltip 连线为什么不显示呢?

// echrts option.tooltip 配置
tooltip: {
  confine: true,
  show: true,
  trigger: 'axis',
  triggerOn: "click",
  alwaysShowContent: true,
  padding: 5,
  backgroundColor: "#EBEBEB",
  borderColor: "#E0E0E0",
  axisPointer: {
    type: "line",
    z: -1,
    lineStyle: {
      color: "#f00",
      width: 1,
      type: "solid",
    },
  },

初始化图表后通过 dispatchAction(type=showTip)可以将 tooltip 及连线(axisPointer) 展示出来:

图片.png

之后通过绑定点击图表事件触发 dispatchAction(type=select)与 dispatchAction(type=showTip)

图片.png

柱子可以被正常 select,tootip 也可以正常显示,但没有连线。但是,如果点击的是表中的柱子,连线也可以正常显示。

接下来,判断点击位置是否在系列柱状图上,如果点击位置不在柱子上就不 dispatchAction:

const pointInPixel = [params.offsetX, params.offsetY];

if (!MyChart.containPixel({seriesIndex: [0]}, pointInPixel)) { 
    return
}

但是,当我点击柱子上方空白位置或者横坐标下的空白位置,虽然没有触发 dispatchAction,但已经选中的 tooltip 的连线会消失。

请问:

  1. 如何在 dispatchAction(type=showTip) 出现连线呢?
  2. 或者如何在后一种情况下控制 tooltip 连线不消失呢?
阅读 1.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题