Chart.js 销毁前自定义插件

Chart.js custom plugin before destroy

我必须通过调用 this.chart.destroy(); 手动销毁我的图表实例 我的问题是我有一个自定义插件,它有事件侦听器。当图表被销毁时,它会通知插件,并在插件的销毁调用中调用 chart.canvas.removeEventListener()。但这仅适用于自动销毁,当我手动调用销毁时, canvas 在通知插件之前停止存在。据我所知,销毁前没有 运行 事件,根据 documents 停止和卸载也在销毁后调用。

有没有办法在销毁图表之前有一个事件?或者是在插件之外处理它的唯一方法,例如手动卸载插件?如果是后者,我认为是bug

Chart.js版本:3.5.1 编辑:对版本 3.6.1 也不起作用。

我也做了一个workaround by placing the event listener removers to reset, and doing this.chart.notifyPlugins('reset') before this.chart.destroy(), so I can check if (chart.canvas) on plugin destroy. This is however just a workaround and I should not have to rely on manual removing, so I filed a bug ticket