chartjs / chartjs-plugin-zoom

Zoom and pan plugin for Chart.js
MIT License
596 stars 327 forks source link

When i use Web Worker, i get 'window is not defined'. #738

Open Quska45 opened 1 year ago

Quska45 commented 1 year ago

Hi. i really enjoy your work in chartjs zoom plugin. Thank you.

But i have some ploblem use web worker.

When i use Web Worker, i get 'window is not defined'.

You have some idea this situation?

I use vite.

LeeLenaleee commented 1 year ago

This is correct, the window object is not available in web workers, which version of chart.js and zoom plugin are you using?

This is correct, the window object is not available in web workers, rendering the chart in an offscreen canvas will return a static image of the chart and not an interactable chart. So the zoom plugin has 0 added value in this case. You can disable the zoom plugin by providing false for the zoom section in the plugins options.

Quska45 commented 1 year ago

Thank you for reply. I think that you mean zoom plugin not available In web worker and offscreen both. If I tried to use only offscreen, but even then, zoom plugin will not work? I want to handle huge data, so i really need web worker and offscreen. If you dont mind, please give some advice for this.

LeeLenaleee commented 1 year ago

If you want to use offscreen canvas API (which you need in webworkers) you can't use the zoom plugin, so you will have to choose which one you want.

You can take a look at this page for some performance tips: https://www.chartjs.org/docs/master/general/performance.html

pjaleeuwen commented 1 year ago

Disabling the zoom plugin via 'options.plugins.zoom = false' does not prevent the error from happening. Dito for options.plugin.zoom.zoom.