Anonymous
Сумма в каждом баре
Сообщение
Anonymous » 16 янв 2025, 22:52
Цель:
В верхней части каждой полосы должна быть указана общая сумма. Например, общая сумма велосипеда равна 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
1737057135
Anonymous
Цель: В верхней части каждой полосы должна быть указана общая сумма. Например, общая сумма велосипеда равна 23. [img]https://i.sstatic.net/Tpqyhw1J.png[/img] < /p> Проблема: Можно ли это сделать в этой диаграмме? Другое: https://jsbin.com/leduqarini/edit?html,output [code] 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 } } } }); [/code] Подробнее здесь: [url]https://stackoverflow.com/questions/79362900/sum-in-every-bar[/url]