В верхней части каждой полосы должна быть указана общая сумма. Например, общая сумма велосипеда равна 23.

< /p>
Проблема:
Можно ли это сделать в этой диаграмме?
Другое:
https://jsbin.com/leduqarini/edit?html,output
Код: Выделить всё
ChartJS Stacked Bar Chart Example
GeeksforGeeks
Chart JS Stacked Chart
// Get the drawing context on the canvas
var ctx = document.getElementById("stackedChartID").getContext('2d');
var myChart = new Chart(ctx, {
plugins: [ChartDataLabels],
type: 'bar',
data: {
labels: ["bike", "car", "scooter", "truck", "auto", "Bus"],
datasets: [{
label: 'worst',
backgroundColor: "blue",
data: [17, 16, 4, 11, 8, 9],
datalabels: {
align: "center",
anchor: "center",
font:{
size: "10px",
},
padding: "0px",
color: "#000",
},
}, {
label: 'Okay',
backgroundColor: "green",
data: [14, 2, 10, 6, 12, 16],
datalabels: {
align: "center",
anchor: "center",
font:{
size: "10px",
},
padding: "0px",
color: "#000",
},
}, {
label: 'bad',
backgroundColor: "red",
data: [2, 21, 13, 3, 24, 7],
datalabels: {
align: "center",
anchor: "center",
font:{
size: "10px",
},
padding: "0px",
color: "#000",
},
}],
},
options: {
plugins: {
title: {
display: true,
text: 'Stacked Bar chart for pollution status'
},
},
scales: {
x: {
stacked: true,
},
y: {
stacked: true
}
}
}
});
Подробнее здесь: https://stackoverflow.com/questions/793 ... -every-bar