I need to automatically sort (in descending order) a dataset like this.
const ctx = document.getElementById('bar-chart')
var chart = new Chart(ctx, {
type: 'bar',
options: {
responsive: true,
scales: {
y: {
stacked: true
},
x: {
stacked: true
}
}
},
data: {
labels: ['A','B','C'],
datasets: [{
label: 'Year 2020',
data: [10,20,25],
backgroundColor: '#ff0000'
},{
label: 'Year 2021',
data: [15,15,10],
backgroundColor: '#00ff00'
},{
label: 'Year 2022',
data: [30,5,25],
backgroundColor: '#0000ff'
}]
}
})
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<canvas id='bar-chart'></canvas>
Is there a chartjs plugin with capability to automatically change sorting in accordance with label currently shown or the unique possible approach is to sort data before to render them?
On other hands this is what I get:

But I would like instead...
- sequence "C","A","B" (having all labels selected)
- sequence "C","B","A" (if only "Year 2020" is selected)