Basically i am creating charts using chart js-node-canvas and here in this charts i want to show my data values on chart
i mentioned image of required chart
Any suggestion or modification to show data-labels (data) on my chart would be helpful Thank you.
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: ['red', 'blue', 'yellow', 'green', 'purple', 'orange']
}]
},.
i want to show this data mentioned in this >> datasets: **[{data: data**
in my chart
my function to generate chart is like these.
async generateChart(data, labels, centerText) {
const chartjsPluginDatalabels = require('chartjs-plugin-datalabels');
try {
const width = 250;
const height = 250;
const chartJSNodeCanvas = new ChartJSNodeCanvas({ width, height });
const configuration = {
type: 'doughnut',
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: ['red', 'blue', 'yellow', 'green', 'purple', 'orange']
}]
},
options: {
plugins: {
datalabels: {
color: 'white',
font: {
size: 16
},
formatter: function(value, context) {
return context.chart.data.labels[context.dataIndex] + ': ' + value;
}
}
},
cutout: '80%',
circumference: 1 * Math.PI,
rotation: -Math.PI,
layout: {
padding: {
top: 20,
bottom: 20
}
},
responsive: false,
maintainAspectRatio: false
}
};
const dataUrl = await chartJSNodeCanvas.renderToDataURL(configuration, { toBase64: true });
const base64Image = dataUrl;
return base64Image;
} catch (err) {
console.log('Error generating chart:', err);
throw err;
}
}```