Chartjs-Chart js bar with the highest value is a different color among the rest – React

0👍

You have to call function giving conditional array of colors for in the place of backgroundColor: ["#33AF4F"]

taking into consideration that you want highest value with different color create this function before rendering component.

function getBgColors() {
  var array  = [2,0,3,4,5,8,7,8,9,10,11,12,11,10,9,6,7,8,7,5,4,3,2,8];
  var maxValue = Math.max.apply(this, array);

  var bg = array.map(a => a === maxValue ? "#0f7d28" : "#33AF4F");
  return bg;
}

and call this function at backgroundColor: getBgColors()

Leave a comment