How to integrate below plugin in ng2-charts:
Do you find the answer for this ? I need
How to integrate below plugin in ng2-charts:
@hadpro24 No I didn't find solution yet but I move on due to inactivity 馃憤
Ok. I already find solution
@hadpro24 Would you mind sharing solution here for other community members then we can close this issue
Insall plugin
npm install chartjs-plugin-datalabels --save
````
Use this
```js
import * as pluginDataLabels from 'chartjs-plugin-datalabels';
In your class
public pieChartPlugins = [pluginDataLabels];
public options = {
tooltips: {
enabled: false
},
responsive: true,
plugins: {
datalabels: {
formatter: (value, ctxt) => {
let percentage;
let datasets = ctxt.chart.data.datasets;
if(datasets.indexOf(ctxt.dataset) === datasets.length - 1) {
let sum = datasets[0].data.reduce((a, b) => a + b, 0);
let percentage = Math.round((value / sum) * 100) + '%';
return percentage;
} else {
return percentage;
}
},
color: '#fff',
}
}
}
In your html
<canvas baseChart
[data]="data"
[labels]="labels"
[chartType]="chart_type"
[options]="options"
[plugins]="pieChartPlugins"></canvas>
thanks @hadpro24
Most helpful comment
Insall plugin
In your class
In your html