how to sort by data in chart js


const arrayOfObj = chartLabels.map(function (d, i) {
return {
label: d,
data: chartValues[i] || 0,
}
})

const sortedArrayOfObj = arrayOfObj.sort(function (a, b) {
return b.data - a.data
})

let newArrayLabel = []
let newArrayData = []
sortedArrayOfObj.forEach(function (d) {
newArrayLabel.push(d.label)
newArrayData.push(d.data)
})

www.codegrepper.com
www.stackoverflow.com