I have this array in react
const pallete = ['#5931B5', '#7842F5', '#2EABE3', '#F2711C']
I want to create a function that will return the first hex, and then the second...
getColor(){
//What code should I have here?
return COLOR
}
This is my main function
updateArray(data){
const dataAux = data;
for(var key in dataAux.datasets) {
if (typeof dataAux.datasets[key].backgroundColor == 'undefined'){
//I want here to take the values from the first array (pallete) and give dataAux.datasets[key]... the first color, then when he reads it again the second one...
for(var i in pallete){
dataAux.datasets[key].backgroundColor = getColor(color????);
}
}
}
}
The const Data have an array of objects something like this:
{labels: [1, 2, 3], datasets: [{label: 'Undefined', pointStyle: 'line', borderColor: pallete[0],borderWidth: 3,yAxisID: "bar-y-axis",data: [1, 2, 3]},{label: 'Undefined',backgroundColor: pallete[1],pointStyle: 'line',borderColor: pallete[1],borderWidth: 3,yAxisID: "bar-y-axis",data: [2, 4, 6]}]}