2016-09-01 2 views
0

매우 익숙하지는 않지만 한 번만 알려 드리겠습니다. Visual Studio에 ASP.Net MVC 웹 응용 프로그램이 있으며, 내보기 중 하나에서 세부 정보보기 아래 제시된대로 색상을 나타내는 이야기. 이 눈금은 녹색과 빨간색으로 만 표시됩니다. 노란색으로 0 %, 녹색으로 100 % 빨강으로 표시하고 중간에서 녹색으로 변경하려면 75 %가 녹색/노란색으로 변경됩니다. 어떤 식 으로든이 문제를 해결하기 위해 아래 코드를 (많이 변경하지 않고) 변경할 수 있습니까? 나는 그것이 올바르게 상태의 값에 따라 색상을 변경하려면 어떻게 이해한다면 ASP.Net 웹 응용 프로그램 표의 색상 변경하기

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> 

답변

0

(I 심하게 설명하면 어떤 도움을 많이 감사하고 죄송)? 몇 가지 예를 들어 주시겠습니까?

상태가 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) 

당신이 운동 솔루션에 도움이 될 것입니다 상태의 예와 약간의 기대 값을 넣으면 .

업데이트

안녕, 코드를 다음, 당신이 뭔가를 구현할 수 있습니다 참조하십시오. public void printColours (double apercentage) { 이중 비율 = apercentage/100; double yellowPercent = (백분율 < 0.25) 0 : (백분율> = 0.25 & & 백분율 < = 0.50)? 백분율 * 2 : ((1.0 - 백분율) * 2);

 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

내가/오렌지, 37, 노란색, 오렌지색으로, 25 레드로 0이 빨간색으로 할 것이 도움이 50, 75, 녹색이 될, 그리고 그것을 확장/노란색, 녹색, (100) inbetween 기본적으로, 그래서 방정식에 노란색을 추가하고 싶습니다. – Gabc

+0

0 % 빨간색은 255, 노란색은 0, 녹색은 0, 25 %는 122와 빨간색 122, 녹색은 0이어야합니다. 50 % 노란색은 255이어야하고 녹색 0 빨간색 0, 노란색 75 % 122, 녹색 122, 빨간색 0 100 % 녹색 255 노란색 0 빨간색 0 잘하면 그게 설명해. – Gabc