I am creating a functionality to create the image like this Image link I mean that I want to display the color like
- 0 %-1 % green to light green
- 1%-3% yellow to light yellow
- 3%-5% orange to light orange
- 5% - 6 red to dark red
Currently, I think it is only possible with the if else condition.
I am doing this in the following way:
function getBackground($val) {
if($val<=0.3)
return "#0A3A0A";
if($val< 0.5)
return "#1E4E1E";
if($val< 1)
return "#508050";
if($val< 1.4)
return "#FFFF0A";
if($val< 1.8)
return "#FFFF1E";
if($val< 2)
return "#FFFF32";
if($val< 2.4)
return "#FFFF46";
return "red";
}
and in html in this way. It is in loop 1-15
$class=getBackground($val);
echo "<li style='background:{$class}'>{$val}%</li>";
but I don't think this is a good solution, because I have to create if else for every condition .
Is there a better way to do this? if yes, then please suggest it to me.
Update:
Main issue is:
The colors will behave like this if it is 0.2% the color will bright green and if it is o.6% it will light green and so on. If it is 0.9% it will lighter green .
I am looking for a solution to show different color like if value is 0.1 then dark green , if it is 0.1 less dark green ................. 0.9 the lighter green . similarly if val is 1.1 then dark yellow. if it is 1.2 less dark yellow........ 1.9 lighter yellow. something like this