Basic
const config = {
type: 'doughnut',
data,
options: {
aspectRatio: 2,
plugins: {
annotation: {
annotations: {
annotation
}
}
}
}
};
const annotation = {
type: 'doughnutLabel',
content: ({chart}) => ['Average',
average(chart).toFixed(2),
'on last ' + chart.data.labels.length + ' months'
],
font: [{size: 60}, {size: 50}, {size: 30}],
color: ['black', 'red', 'grey']
};
function average(chart) {
const values = chart.data.datasets[0].data;
return values.reduce((a, b) => a + b, 0) / values.length;
}
const DATA_COUNT = 12;
const MIN = 0;
const MAX = 100;
const numberCfg = {count: DATA_COUNT, min: MIN, max: MAX, decimals: 0};
const data = {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
datasets: [{
data: Utils.numbers(numberCfg)
}]
};