Comments (1)
Unfortunately, chartjs-plugin-datalabels does not play nice in a dual CommonJS/ESM environment using Node.js. I was having a bear of a time trying to get labels to work properly with ESM and Node.js. I could get the labels to display but could not get them in their correct location due to failure of "instanceof" in one of the modules. That was due to the plugin loading in CommonJS mode rather than ESM mode. I did try creating a simple package.json in the "dist" directory with
{
"type": "module"
}
which did work but broke CommonJS support. Ultimately, after some hacking in the chartjs-plugin-datalabels directory of node_modules, I came up with a workable solution though it will get wiped if I ever do an "npm update".
First I add the following to the package.json file:
"exports":{
"import":"./dist/chartjs-plugin-datalabels.esm.mjs",
"require":"./dist/chartjs-plugin-datalabels.js"
},
Then I copy chartjs-plugin-datalabel.esm.js to chartjs-plugin-datalabel.esm.mjs. Once that is done, both CommonJS and ESM routines work fine. The crazy thing is that within the package.json file there is an entry that says
"module": "dist/chartjs-plugin-datalabels.esm.js",
IMHO, this would solve the problem of CommonJS/ESM interoperability with Node.js EXCEPT, Node.js ignores the "module" property of package.json [rolls-eyes]. So the best solution at this time is to add the "exports" property and make a .mjs copy of the ESM module.
from chartjs-plugin-datalabels.
Related Issues (20)
- TypeError of datalabels in case stacked100 is enabled HOT 5
- Type of font.size might be wrong on the options page.
- Feature Request: option to handle when label cannot fit inside a bar HOT 1
- vite not insert page ref in manifest.json if I include chartjs-plugin-datalabels HOT 1
- When using with zoom plugin, `clip: true` affect the labels on the edge
- Chartjs .js and .cjs are both imported when using chartjs-plugin-datalabels
- FR: Images and/or Text
- Problem display datalables using Chart.js 4.4.0 HOT 2
- Not compatible with Chart.js 4.4.1 HOT 2
- Add boolean property to match the Datalabels color with the corresponding line/bar color
- Not working with Chart.js 4.4.1 (latest)
- Cant align plugins.legent.labels correctly
- Horizontal stacked barchart with negative values label position is off
- letterSpacing option is not working
- Line or arrow towards data point? HOT 1
- Crashes on Chart.js 4.4.1 and 4.4.0 HOT 3
- Update datalabels when chart is updated.
- know if a label is clipped?
- Display Error when using data labels and min and/or max values for the x-axis HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chartjs-plugin-datalabels.