Dynamic Chart.js backgroundColor

Hi all,
is it possible to have a dynamic “backgroundColor”?

Not like this:
backgroundColor: [
‘rgb(255, 99, 132)’,
‘rgb(255, 159, 64)’,
‘rgb(255, 205, 86)’,
‘rgb(75, 192, 192, 192)’,
‘rgb(54, 162, 162, 235)’,
],

it would look something like this:
backgroundColor: [ dinamicColor( n ) or url? ],

Thanks!

Yes, you can do this using a Javascript function.

For example, this will randomize the order of the background colors:

{
  type: 'bar',
  data: {
    labels: ['Q1', 'Q2', 'Q3', 'Q4'],
    datasets: [{
      label: 'Users',
      data: [50, 60, 70, 180],
      backgroundColor: () => {
        const colors = ['red', 'green', 'blue', 'yellow'];
        return colors.sort(() => Math.random() - 0.5);
      },
    }, {
      label: 'Revenue',
      data: [100, 200, 300, 400]
    }]
  }
}

Example in chart editor