0

我想实现类似于 Excel 中的“色阶”功能的简化结果,即基于最小值(红色)到最大值(绿色)的渐变着色,除了在我使用 Crystal Reports 2008 的交叉表中。我的交叉表看起来有点像这样:

 HOURS    L1   L2  L3   L4  Total
 1 hours | 5 | 0 | 1 | 16 | 22 |
 2 hours | 0 | 1 | 0 | 10 | 11 |
 3 hours | 8 | 2 | 6 | 12 | 28 |
 TOTAL   |13 | 3 | 7 | 38 | 61 |

我的功能原理是在交叉表中找到最大值,然后使用 20%、40%、60%、80% 的值来为背景着色。功能如下(在格式>背景部分):

    if currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.2) then color(255,0,0)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.2) and 
        currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.4)) then color(255,192,0)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.4) and 
        currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.6)) then color(255,255,0)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.6) and 
        currentfieldvalue < ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.8)) then color(146,208,80)
else if (currentfieldvalue >= ((Maximum (MakeArray (CurrentColumnIndex, CurrentRowIndex, 1)))*0.8)) then color(0,176,80)

它不优雅,也不能正常工作,任何帮助/建议将不胜感激。我没想到它会如此复杂,因为我最初使用下面的假设它会起作用,但它告诉我“CurrentFieldValue”不是一个字段。

if CurrentFieldValue < ((Maximum (CurrentFieldValue))*0.2) then color(255,0,0)
else if ... etc.
4

1 回答 1

0

在这篇文章的帮助下:对于每个交叉表列,突出显示最大值,我设法得到了我想要的结果。希望这对其他人有帮助。干杯。

local Numbervar max:=0;
local Numbervar col;
local Numbervar row;

for col := 0 to GetNumColumns-2 do 
(
    for row := 0 to GetNumRows-2 do 
    (
        local numbervar value := GridValueAt (row, col, CurrentSummaryIndex);
        if value > max 
            then max := value;
    );
);

ToText(max,"#");

// Reference Red 248,105,107
// ReferenceGreen 99,190,132

local Numbervar cRed;
local Numbervar cGreen;
local Numbervar cBlue;

cRed := Floor(99 + 149 * (1-(GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0)/max)));

cGreen := Floor(105 + 85 * (if (((GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0)/max))*10) > 1 then 1));

cBlue := Floor(107 + 25 * ((GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0)/max)));

color(cRed, cGreen, cBlue)
于 2012-10-08T15:35:16.463 回答