I have a chart where I need to display a different bar for each relevant year that comes up. Prior to running a query, I have no idea what years will be returned and displayed. I need each year bar to have it’s own unique color that is visibly distinguishable from other years. I also need to be able to reproduce the results of the method (for example, 2011 would always return some exact shade of green). Ideally, I would have a simple method that looks like this:
public static Color GetColorFromYear(int year)
{
// Some magic.
}
I guess there are probably easy ways to convert an integer to a color value, but I’m hoping someone has solved this problem in a way that produces a nice color scheme and distinguishable colors. Thanks in advance!
I would just use a cycle of colors by taking the modulus of the year, for however many colors you want to use:
If you want to generate some rainbow of colors, you could use a loop sequence with
Color.FromArgbto generate a gradient of colors. This can be adapted to different levels of gradients or different color schemes by changing the for loop parameters and the various components of red, green, and blue.