silkfire Posted September 19, 2011 Share Posted September 19, 2011 Hello folks. I have a system showing stock of products. Now I want to colorize the value based on how much it is. For example 0 is red and then green is 10 000 and up. So the range should be like a smooth gradient. What's the algorithm? Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 19, 2011 Share Posted September 19, 2011 How is this a PHP Coding Question? The "algorithm?". Well, that would depend on what "red" and what "green" you want to use. It would be presumptuous for me to assume that you want to use the red "FF0000" or the green "00FF00". That red is probably a safe bet, but the "full" green is a pukey lime green. A better choice might be something closer to a hunter green such as "008000". Assuming those are the two colors you will use. The red parameter goes though the full 256 values and the green goes through 128 values. 10,000 / 256 = 39 10,000 / 128 = 78 So, starting with 00FF00"" for 0 units, for every 39 units you would subtract 1 from the red component of the color code and for every 78 units you would add 1 to the green component. I'll let you figure out the programming. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.