Answers for "how to sort by data in chart js"

0

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)
  })
Posted by: Guest on October-01-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language