How Can I Make Bar Charts Symmetrical In Chart.js?
I have a horizontal bar with two datasets to show a simple age pyramide. I'm using negative values for female and positive values for male How do I make the bars from both dataset
Solution 1:
Baha, é só colocar a propriedade scales stacked true
new Chart(document.getElementById("ProdFicha_Idade"), {
type: 'horizontalBar',
data: {
labels: ["18-25", "25-30", "30-35", "35-40"],
datasets: [
{
data: [1,2,3,4],
label: "Male",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
},
{
data: [-1,-2,-3,-4],
label: "Female",
backgroundColor: ["blue", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"]
}
]
},
options: {
title: {
display: true,
text: 'Pyramide des ages'
},
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true
}]
}
}
})
Post a Comment for "How Can I Make Bar Charts Symmetrical In Chart.js?"