Chart.js Plugin Labels for Chart.js v3+
Chart.js plugin to display labels on pie, doughnut and polar area chart. Forked from emn178/chartjs-plugin-labels.
Demo
- Demo from the original repo using Chart.js v2.x, but it's almost the same.
Download
CDN Link
You can put the below link in the script tag
https://unpkg.com/chart.js-plugin-labels-dv/dist/chartjs-plugin-labels.min.js
Installation
npm i chart.js-plugin-labels-dv
Usage
JavaScript
new Chart(ctx, {
type: type,
data: data,
options: {
plugins: {
labels: {
render: 'value',
precision: 0,
showZero: true,
fontSize: 12,
fontColor: '#fff',
fontStyle: 'normal',
fontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
textShadow: true,
shadowBlur: 10,
shadowOffsetX: -5,
shadowOffsetY: 5,
shadowColor: 'rgba(255,0,0,0.75)',
arc: true,
position: 'default',
overlap: true,
showActualPercentages: true,
images: [
{
src: 'image.png',
width: 16,
height: 16
}
],
outsidePadding: 4,
textMargin: 4
}
}
}
});
{
render: function (args) {
return '$' + args.value;
}
}
{
fontColor: function (args) {
return myColorTransfer(args.dataset.backgroundColor[index]);
}
}
Support multiple options, eg.
labels: [
{
render: 'label',
position: 'outside'
},
{
render: 'value'
}
]
Global options
Chart.defaults.global.plugins.labels = {
};
Angular
- Install using
npm i chart.js-plugin-labels-dv
- Edit
angular.json
and add inside the "scripts"
array: "node_modules/chart.js/dist/chart.min.js"
- Inside the component where you want to use Chart.js:
import Chart from 'chart.js/auto';
License
MIT license.
Contact
The project's website is located at https://github.com/emn178/chartjs-plugin-labels
Authors: Chen, Yi-Cyuan (emn178@gmail.com), Davide Violante