echarts showTip持续显示

学习自

https://github.com/apache/echarts/issues/9242

tooltip设置alwaysShowContent,悬浮上去后会一直显示

tooltip: {
    
    
   trigger: 'axis',
   alwaysShowContent: true,
},

seriesIndex表示是series的第几个,dataIndexdata属性的索引
我这里的需求是固定显示最后一个数据的tooltip,给外层div绑定一个mouseleave,鼠标移开后调用dispatchAction触发tooltip

 <div
      class="echarts-div"
      @mouseleave="dispatchAction">
      <Echarts
        class="real-echart"
        :option="option"
        autoresize
        ref="chart"></Echarts>
    </div>
watch: {
    
    
    option: {
    
    
      handler() {
    
    
        this.$nextTick(() => {
    
    
            this.$refs.chart.dispatchAction({
    
    
              type: 'showTip',
              seriesIndex: 0,
              dataIndex:
                Math.max(
                  ...this.option.series.map((item) => item.data.length)
                ) - 1,
            });
        });
      },
      deep: true,
    },
  },
  methods: {
    
    
    dispatchAction() {
    
    
      this.$refs.chart.dispatchAction({
    
    
        type: 'showTip',
        seriesIndex: 0,
        dataIndex:
          Math.max(...this.option.series.map((item) => item.data.length)) - 1,
      });
    },
  },

猜你喜欢

转载自blog.csdn.net/qq_42611074/article/details/133316721