最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

chart.js - How can I make my custom plugin execute before the Tooltip plugin? - Stack Overflow

programmeradmin2浏览0评论

I have written a custom plugin for ChartJS v4 in my application, and I am instantiating it in my chart instance like this:

new Chart(myCanvas, {
    plugins: [
        new MyPlugin(...)
    ],
    //rest of the configuration
});

This works, however I have a problem: my plugin draws on the chart's canvas, and since I also have Tooltips enabled (which in ChartJS is itself a plugin) what happens is:

  • The chart area is drawn
  • The Tooltip plugin draws the tooltip
  • My plugin draws on the canvase Result: my plugin is drawing on top of the tooltips.

How can I avoid this? Is there a way to specify the order of execution of plugins?

NOTES:
1 - My plugin needs to be instantiated inline like in the example above, because its constructor needs some parameters that are not known beforehand, so I cannot register it globally
2 - I tried doing this instead (define the Tooltip plugin inline instead of globally) but in this way the Tooltip plugin doesn't seem to work:

new Chart(myCanvas, {
    plugins: [
        new MyPlugin(...),
        Tooltip
    ],
    //rest of the configuration
});
发布评论

评论列表(0)

  1. 暂无评论