emn178 / chartjs-plugin-labels

Plugin for Chart.js to display percentage, value or label in Pie or Doughnut.
MIT License
616 stars 218 forks source link

how to add this to chart.js #131

Open ghost opened 4 years ago

ghost commented 4 years ago

i am new to this. and i need more details about how to use it. help

got2ski commented 4 years ago

This worked for me. In config.json have externals point to recent libraries in node_modules. Set a global dependency for chartjs-plugin-labels on chart.js with a shared global name. The charts.js has to load first before the chartjs-plugin-labels.js as stated in earlier issues. Read these, they helped me, https://github.com/emn178/chartjs-plugin-labels/issues/47 https://github.com/emn178/chartjs-plugin-labels/issues/79

"externals": { "sp-client-custom-fields": "node_modules/sp-client-custom-fields/dist/sp-client-custom-fields.bundle.js", "jquery": { "path": "node_modules/jquery/dist/jquery.min.js", "globalName": "jQuery" }, "chartjs": { "path": "node_modules/chart.js/dist/Chart.min.js", "globalName": "Chart" }, "chartlabelsjs": { "path": "node_modules/chartjs-plugin-labels/src/chartjs-plugin-labels.js", "globalName": "Chart", "globalDependencies": ["chartjs"] }
},

Add a require for chartjs-plugin-labels with chart.js just under the imports of the TS file.

var Chart: any = require('chartjs'); require('chartlabelsjs');

image