chartjs-plugin-labels
Chart.js plugin to display labels on pie, doughnut and polar area chart. Original Chart.PieceLabel.js
Demo
Demo
Download
Compress
Uncompress
Installation
You can also install chartjs-plugin-labels by using Bower.
bower install chartjs-plugin-labels
Or node.js, you can use this command to install:
npm install chartjs-plugin-labels
Notice
v1.0.0 has breaking changes. Please see CHANGELOG v1.0.0
v0.7.0 has deprecated options. Please see CHANGELOG v0.7.0
v0.4.0 has breaking changes. Please see CHANGELOG v0.4.0
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 = {
};
For Angular 2+
If you use angular2-chartjs, you can import by this:
import { ChartModule } from 'angular2-chartjs';
import 'chartjs-plugin-labels';
License
The project is released under the MIT license.
Contact
The project's website is located at https://github.com/emn178/chartjs-plugin-labels
Author: Chen, Yi-Cyuan (emn178@gmail.com)