Hi guys,
I create this stacked bar chart config like below and I use formatter to get rid of 0 value. I don’t know why 0 value still display
{
“type”: “bar”,
“data”: {
“labels”: [“INV-C”, “CAT-CORE”, “PILOT-BVT”],
“datasets”: [
{
“label”: “Passed”,
“data”: [6, 29, 114],
“backgroundColor”: “rgba(76, 175, 80, 0.2)”,
“borderColor”: “rgba(76, 175, 80, 1)”,
“borderWidth”: 1
},
{
“label”: “Failed”,
“data”: [1, 0, 15],
“backgroundColor”: “rgba(244, 67, 54, 0.2)”,
“borderColor”: “rgba(244, 67, 54, 1)”,
“borderWidth”: 1
},
{
“label”: “Broken”,
“data”: [0, 1, 10],
“backgroundColor”: “rgba(255, 193, 7, 0.2)”,
“borderColor”: “rgba(255, 193, 7, 1)”,
“borderWidth”: 1
}
]
},
“options”: {
“scales”: {
“y”: {
“beginAtZero”: true,
“stacked”: true
},
“x”: {
“stacked”: true,
“ticks”: {
“maxRotation”: 0,
“minRotation”: 0,
“autoSkip”: false,
“font”: {
“size”: 10
}
}
}
},
“layout”: {
“padding”: 10
},
“plugins”: {
“legend”: {
“display”: true
},
“datalabels”: {
“display”: “function(context) { const index = context.dataIndex; const value = context.dataset.data[index]; return value > 0; }”,
“color”: “#000”,
“anchor”: “center”,
“align”: “center”,
“offset”: 8,
“clip”: false,
“font”: {
“size”: 10,
“weight”: “bold”
}
}
}
}
}