[Chartjs]-Cycle through finite set of colours for indefinite set of data in Javascript

6👍

You can switch out the colors array with a doubly-linked list.

Or just use an anonymous function on the object creation,

datasets: [{backgroundColor: (() => {
  let bgcolors = [];
  for (let i=0; i < tickers.length; ++i) bgcolors.push(colors[i % colors.length]);
  return bgcolors;
  })()
}]

Leave a comment