I have a vertical bar chart built via chartjs. I'm using the datalabels plugin, I expect the data to be plotted on each bar but it's not visible
const data = [
{
"date": "2023-02-23",
"subscribers": 1208123
},
{
"date": "2023-02-22",
"subscribers": 1045338
},
{
"date": "2023-02-21",
"subscribers": 1043130
},
{
"date": "2023-02-20",
"subscribers": 1248035
},
{
"date": "2023-02-19",
"subscribers": 1243734
},
{
"date": "2023-02-18",
"subscribers": 1240317
},
{
"date": "2023-02-17",
"subscribers": 1033439
},
{
"date": "2023-02-16",
"subscribers": 974864
}
];
const chart_label = "Number of subscribers";
const chart_canvas = document
.getElementById("number_of_messages_delivered")
.getContext("2d");
Chart.defaults.set("plugins.datalabels", {
color: "#FE777B",
});
push_messages_chart = new Chart(chart_canvas, {
type: "bar",
options: {
animation: true,
plugins: {
// Change options for ALL labels of THIS CHART
datalabels: {
color: "#FFCE56",
display: true, // Set to true to display the labels
},
},
},
data: {
labels: data.map((row) => row.date),
datasets: [
{
label: chart_label,
data: data.map((row) => row.subscribers),
},
],
},
});
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.0.0/dist/chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.2.0/chartjs-plugin-datalabels.min.js"></script>
<canvas id="number_of_messages_delivered"></canvas>
I tried different iterations since last week, but nothing worked. This is just a random sample of what I've tried