Value-driven Color
There are times when you want to display a graph of data and add meaningful colors based on their values. Such as the one below.
What we can do is to put a fixed number of colors, and use a switch statement with their case statement as ranges.
What if we wanted a gradual change of colors, with a unique color corresponding to each value? Moreover, what if the y-values are not always 100?
My solution comes down in calculating each component of the RGB values of the resulting color, with the desired intermediate colors hard-coded.
This approach gets the job done, but from a design point of view, I personally like finite number of colors. In fact, the app that is shown in this blog post is currently using a finite number of colors. These colors are the template colors in the Sketch app, and I thought they looked beautiful.