-
I'm trying to get this plugin to work, but really getting nowhere. I have installed it from npm, and configured Laravel mix (webpack front-end) to bundle mix.js(
[
'node_modules/chart.js/dist/chart.js',
'node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.js'
],
'public/js/chart.js'
); I can see that this does indeed include the source of both packages in the target file. I then load that into my page with a script tag. I can create
If I remove the
If I do neither of those, I just get a I'm sure I must be be missing something very basic, but I don't know what. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Not sure if it might work but you can try to import everything and see if the import * as datalabels from 'chartjs-plugin-datalabels';
Chart.register(datalabels.ChartDataLabels); |
Beta Was this translation helpful? Give feedback.
-
Thanks for replying. Unfortunately this fails in a similar way: import * as datalabels from 'chartjs-plugin-datalabels';
SyntaxError: Unexpected token '*'. import call expects exactly one argument. That was in Safari; Chrome gives a slightly more useful error message:
So I guess I'm not using a module? FWIW, this is my combined JS file (it's in dev mode so not minified). |
Beta Was this translation helpful? Give feedback.
-
When I look at the generated source file, I can see that webpack has stripped out the definition of |
Beta Was this translation helpful? Give feedback.
-
I've come to the conclusion that you can't use mix except as a means of copying files into place separately, like this: mix.copy(
[
'node_modules/chart.js/dist/chart.js'
],
'public/js/chart.js'
);
mix.copy(
[
'node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.js'
],
'public/js/chartdatalabels.js'
); and then loading each script from a separate scrip tag. Combining the files stops it working, so don't do that. When I use this approach I don't seem to need to do any of the registration steps described in the docs as both |
Beta Was this translation helpful? Give feedback.
I've come to the conclusion that you can't use mix except as a means of copying files into place separately, like this:
and then loading each script from a separate scrip tag.
Combining the files stops it working, so don't do that.
When I use this approach I don't seem to need to do any of the registration steps described in the docs as both
Chart
andChartDataLabels
are immediately available in the global scope. I don't understand why this simple appr…