hello everyone i am creation a dashboard that contains bar chart using Angular 7 ,chart.js and chartjs-plugin-datalabels
as you can see in the picture the bar chart contains different data sets each one has it's own label i wanted to show the label on each one on top of the bar and its value but i did not know how my code only shows me the label of data-set
what i mean is as you can see in my code (.ts) file
this.chartdef= new Chart('defaut',
{
type:'bar',
options:{
cutoutPercentage:40,
responsive :true,
title:{
display:true,
text:'TRG VAGUE'
},
plugins:{
datalabels:{
align:'top',
display: 'true',
color:'#ffffff',
}
}
},
data:{
labels:['poste1','poste2','poste3'],
datasets:[
{
label:'REPERTOP01',
data:[10,7.5,4.5],
backgroundColor:'rgba(255, 0, 0,1)',
borderColor:'rgba(255, 0, 0,0.6)',
borderWidth:1,
fill:false,
datalabels: {
align: 'end',
anchor: 'end',
formatter: function(value, context) {
return context.chart.data.labels[context.dataIndex];
}
}
},
{
label:'REPERTOP02',
data:[4.5,0,1],
backgroundColor:'rgba(255, 102, 0,1)',
borderColor:'rgba(255, 102, 0,0.6)',
fill:false,
borderWidth:1
},
{
label:'REPERTOP02',
data:[4.5,0,0],
backgroundColor:'rgba(255, 225, 0,1)',
borderColor:'rgba(255, 225, 0,0.6)',
fill:false,
borderWidth:1
}
]
}
})
and html file
<div class="container-fluid">
<canvas id="defaut" height="40px" width="100%">
</canvas>
</div>
i have 3 data-sets i want to show on top of each bar its label i like REPERTOP01
but this code shows me poste1
on top of the bar and also if i show the label the value disappear so how can i show REPERTOP01
instead of poste1
poste2
and poste3
and show the value with it inside the bar