2

I want to load Javascript plugins for chartJS within QLIK Sense Developer.

I have set up the define as below.

define( [
   'jquery',
   './PropertiesPannel',

   '//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.js',
   '//cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js',
   //'./chartjs-plugin-zoom',
   './chartjs-plugin-annontation',
   //'./chartjs-plugin-datalabels',
   'qlik'
],
function ( $, ProperitesPannel, Chart,Hammer,ChartAnnotation,qlik) { foo,baa}
  • Problem 1: ON Qlik App run time, 'Chart' is undefined error is happening for the data labels plugin.
  • Problem 2: ON Qlik App run time, on occasion, the Zoom and annotations plug error as Problem 1

I believe the problem is because the packages are not loading in order so the plugins are loading before main chartJS plugin thus making Chart not globally ready to be used.

How can I load these in a way that will make sure on run time, everything is loaded correctly?

Peachman1997
  • 183
  • 1
  • 12

1 Answers1

1

How can I load these in a way that will make sure on run time, everything is loaded correctly?

This option is called shim. Here quick example:

requirejs.config({
  shim: {
    '//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.js': ['jquery'],
  }
});

In this example I am telling Require to load jQuery before loading Chart.bundle.js because it needs it. For all files which does not AMD support you have to set that.

You can learn more in the official page: https://requirejs.org/docs/api.html#config-shim

Damian Dziaduch
  • 2,107
  • 1
  • 15
  • 16
  • 1
    So I have given this a go and things still seem to not be working. I have used this idea above to go like this. Chart js Requires Hammerjs Plugin 1 requires chartjs plugin 2 requires chartjs This is now throwing more errors than before. I think this could also be something to do with how the plugins are set to export the code as they differ across all 3. – Peachman1997 Jun 23 '20 at 12:57