【问题标题】:Changing colour in ASP.Net web app table更改 ASP.Net Web 应用程序表中的颜色
【发布时间】:2017-01-09 10:44:36
【问题描述】:

对此不是很熟悉,但我会试一试,所以我在 Visual Studio 中有一个 ASP.Net mvc Web 应用程序,在我看来,查看详细信息我有一个根据呈现颜色呈现颜色的故事以下。这个比例只有绿色和红色,我希望它在 0% 时是红色的,在 50% 时是黄色,在 100% 时是绿色,并且要在两者之间变化,所以说 75% 将是绿色/黄色。有什么办法可以改变下面的代码(不做太多改变)来解决这个问题? (如果我解释得不好,任何帮助都非常感谢和抱歉)

    float colorPercentage = ((float)status.Status) / 100;
    int red = (int)(255 * (1 - colorPercentage));
    int green = (int)(255 * colorPercentage);

    <tr>
        <td><a href="#@practiceName">@practiceName</a></td>
        <td style="background-color:rgb(@red,@green,0);color:white">@status.Status%</td>
        <td>@status.Comment</td>
    </tr>

【问题讨论】:

    标签: html asp.net-mvc colors html-table


    【解决方案1】:

    如果我理解正确,您想根据状态值更改颜色吗?可以举个例子吗?

    如果状态为 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
    

    希望对你有帮助

    【讨论】:

    • 我希望 0 为红色,25 为红色/橙色,37 为橙色,黄色 50、75 黄色/绿色和 100 为绿色,并且基本上在两者之间进行缩放,所以我也想在方程式中添加黄色
    • 在 0% 时红色应该是 255,黄色 0 和绿色 0,在 25% 时黄色应该是 122 和红色 122,绿色 0 在 50% 时黄色应该是 255 和绿色 0 红色 0,在 75 % 黄色 122,绿色 122,红色 0 100% 绿色 255 黄色 0 红色 0 希望可以解释一下
    猜你喜欢
    • 2010-12-15
    • 2011-07-02
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多