Echart 屏幕提示框应用

垂直:上下固定,左右移动  这个代码可以实现tooltip在垂直上是固定的,  记得逗号最后一个不需要tooltip: {
                        trigger: 'axis',
                        textStyle: {
                            color: contentColor
                        },
                        axisPointer: { 
                            type: 'shadow' 
                        },
                        position: function(point, params, dom) {
                            return [point[0], '10%'];
                        }

                    },


请问怎么实现垂直上是固定,水平上是auto?

 position: function(point, params, dom) { 
                    var posDis = window.innerWidth - dom.offsetWidth; 
                    return posDis<point[0]?[posDis, '10%']:[point[0], '10%'];

                },

position: function (pos, params, dom, rect, size) {
  let yPos = '20%'
  let xPos = 0
  if (pos[0] < size.viewSize[0] / 2) {
    xPos = pos[0] + 10
  } else {
    xPos = pos[0] - dom.offsetWidth - 10
  }
  return [xPos, yPos]
}



实际应用:

tooltip : {
    position: function(point, params, dom) {
        return [point[100], '20%'];
    },
    // trigger: 'item',
    // formatter: "{a} <br/>{b} : {c} ({d}%)"
    formatter: "{b}  ({d}%)"
},


猜你喜欢

转载自blog.csdn.net/heyuqing32/article/details/80912351