我希望获得类似于Excel中“Color Scale”功能的简化结果,即基于最低值(红色)到最高值(绿色)的渐变着色,但在使用Crystal Reports 2008的交叉表中除外。我的cross tab看起来有点像这样:
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.
答案 0 :(得分:0)
在这篇文章的帮助下:For each crosstab column, highlight maximum value,我设法得到了我想要的结果。希望这对其他人有帮助。欢呼声。
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)