echarts tooltip exceeds container size

2023.10.19 Today I learned how to prevent the prompt box from exceeding the container size in the echarts chart:

code show as below:

 tooltip: {
         
          position: function (point, params, dom, rect, size) {
            let x = point[0] + 10; // x 轴偏移量为 10
            let y = point[1] + 20; // y 轴偏移量为 10
            if (x + dom.offsetWidth > size.viewSize[0]) {
              x = size.viewSize[0] - dom.offsetWidth;
            }
            if (y + dom.offsetHeight > size.viewSize[1]) {
              y = size.viewSize[1] - dom.offsetHeight;
            }
            return [x, y];
          },
}

Just add this to the tooltip

Guess you like

Origin blog.csdn.net/qq_53986004/article/details/133920111