kurkle/chartjs-plugin-autocolors

Alternative Use to Generate Color Array of Desired Length?

GermanPearls opened this issue · 2 comments

Thank you for your plugin. I'd like to extend its use for another area of my project where I need an array of colors of a given length. Is this something I could generate from your existing plugin?
Thank you.

Can you describe the use case more? Is it for chart.js or do you just need an array of colors for something else?

There are multiple ways to do an "one off" using the code from this generator. I think easiest would be to create a chart with as many datasets as you need colors and extract from there.

For example: https://codepen.io/kurkle/pen/poVOWaj

I have a set of items which I'd like to chart, but also potentially locate them on a map, or identify them in a table. The map and table would not be created with chartjs, but with other methods/packages.

As an example, if I had 5 items, I would want an array of 5 colors. I could then plot each item's properties on a chart using those colors, but also locate them on a map (with a colored dot for each item), or add them to a table (like a key with a small color indicator). If they were all rendered on the same page and I was working from a predefined array I could ensure if item A was red on the chart, it's also red on the map, and red in the table. Item B would then be blue on the chart, map, and table.

I think I can work with the way you laid it out in your example.
Thank you for your quick response!