以响应方式在圆环图中间居中 Highcharts 工具提示

Center Highcharts tooltip in the middle of donut chart in a responsive way

在 Highcharts 中,我知道您可以使用以下方法将工具提示放在固定位置:

        tooltip: {
          positioner: function () {
              return { x: 50, y: 50 };
          },
        },

但是我怎样才能像 margin: 0 auto 一样将它居中呢?我试图让工具提示文本留在圆环图的中间。解决方案可能很明显,但我还没有弄清楚它是什么。提前致谢!

您可以使用图表 plotHeightplotWidth 来访问当前图表的高度和宽度,并相应地调整工具提示 x 和 y,如下所示:

positioner:function(){              
 return { x: chart.plotWidth/2, y: chart.plotHeight/2 };
}

这里有一个工作演示:https://angular-raebwk.stackblitz.io