如果我理解正确,您想根据状态值更改颜色吗?可以举个例子吗?
如果状态为 45,红色和绿色的值是多少?如果状态为 75,红色和绿色的值是多少?
如果你想让绿色在状态的基础上增加,红色减少,你可以这样做:
green = (255 / (1/colorPercentage)); //green increases as per the colorPercentage's value
red = 255 - green; (if green is 200 you will get red as 55)
如果您将一些预期值与状态示例放在一起,这将有助于解决问题。
更新
嗨,看下面的代码 sn-p,你可以实现这样的东西。
公共无效打印颜色(双百分比)
{
双倍百分比 = 百分比/100;
double yellowPercent = (percentage =0.25 && percent
double red, yellow, green;
red = 255 * (1.0 - percentage);
green = 255 * (1.0 * percentage);
yellow = 255 * yellowPercent;
System.Diagnostics.Debug.WriteLine(string.Format("Red: {0}, Green: {1} and Yellow: {2} for Percentage of: {3}", red, green, yellow,percentage));
System.Diagnostics.Debug.WriteLine(yellowPercent);
}
你可以测试一下
printColours(10.00);
printColours(25.00);
printColours(40.00);
printColours(50.00);
printColours(60.00);
printColours(65.00);
printColours(75.00);
printColours(95.00);
printColours(100.00);
我从这种方法中获得了以下结果,我认为这应该足够了,请随时根据您的需要进行更改。
Red: 229.5, Green: 25.5 and Yellow: 0 for Percentage of: 0.1
Red: 191.25, Green: 63.75 and Yellow: 127.5 for Percentage of: 0.25
Red: 153, Green: 102 and Yellow: 204 for Percentage of: 0.4
Red: 127.5, Green: 127.5 and Yellow: 255 for Percentage of: 0.5
Red: 102, Green: 153 and Yellow: 204 for Percentage of: 0.6
Red: 89.25, Green: 165.75 and Yellow: 178.5 for Percentage of: 0.65
Red: 63.75, Green: 191.25 and Yellow: 127.5 for Percentage of: 0.75
Red: 12.75, Green: 242.25 and Yellow: 25.5 for Percentage of: 0.95
Red: 0, Green: 255 and Yellow: 0 for Percentage of: 1
希望对你有帮助