11-17-2014 01:44 PM
Hello,
How do I separately control the background color of a given cell of a table using a script for a 2Dtable in the report?
I am able to color only the whole line...
Thank you very much,
Best regards,
Louval
11-17-2014 05:06 PM
Louval
My approach to solve this was to make Separate Tables for each column. Then set the positions for each table so that it appears like one table.
The display screen allows setting of the positions more precisely than the mouse can. I positioned all the tables using this option.
Paul
ps. Also developed a report page configurator Class so that can just call out the table name and positions, It then makes the tables real consistent. Let me know if this would help, and I will post it.
11-18-2014 05:06 AM - edited 11-18-2014 05:17 AM
Hi louval,
you can do this by adding a "usercommand" to your DIAdem, and then configure it to your columns. The command should look like this:
Function TabColorCol(ByVal Value) 'color stuff If (Value > 8) Then D2TabNumColor(D2TabCol) = "dark green" ElseIf (Value < 6) Then D2TabNumColor(D2TabCol) = "red" Else D2TabNumColor(D2TabCol) = "black" End If 'value editing If (IsNull(Value)) Then TabColorCol= "" Else TabColorCol= Round(Value, 1) End If End Function
Simply add this function to a VBS and register this VBS to your usercommands.
In the Report you can call the function in the columnsettings -> format like this:
@@TabColorCol(CFV)@@
Edit:
Sorry, but i only can set the color of the text, i can't find a background-setting for a column
11-18-2014 05:50 AM
Hi louval
In DIAdem 2014 you can also set the color of individual cells. You can find an eplanation here:
In the help examples of version 2014 (Help > Examples>New Examples>Version 2014 >Trend display ..) you will find an example how it looks and works.
If you only want to change the color of columns or rows you can change the colors in the dialog box.
Hope this works
Winfried
11-18-2014 01:02 PM
Dear All,
Thank you very much for your answers.
However, all these elements are not enough.
I see that one only uses "If then Else" conditioning in the sub routine. What I want to do is to loop over the cells like, if i are row and j the column,
For i=1:end
For j= 1: J
If X1,j < Xi,j < X2,j then
color the cell in green
Else
color it in red
Endif
End
End
In this example, the first and second row of my table contains the limits for each value in i+2 to I.
It is tricky to me as I do not understand how diadem loop itself over the cell since one can access context.Row and Col.
Please help me...
Thank you,
Louval
11-19-2014 12:34 AM
Hi Louval,
in every example DIAdem loops through all cells. Take my snippet for example, the function is called in every cell when its been drawed. You can check the row-number with the variable D2TabRow. My suggestion is to check the limits via the data portal.
Function TabColorCol(ByVal Value) 'set channel object Dim oChn : oChn = Data.Root.Channelgroups("GroupA").Channels(D2TabChnName(D2TabCol)) 'color stuff If (D2TabRow > 2) Then If (oChn(1) < Value) AND (oChn(2) > Value) Then D2TabNumColor(D2TabCol) = "dark green" Else D2TabNumColor(D2TabCol) = "red" End If End If 'value editing If (IsNull(Value)) Then TabColorCol= "" Else TabColorCol= Round(Value, 1) End If End Function
<script src="ms-its:diadem.chm::/FeedbackLink.js" type="text/javascript" language="JavaScript1.2"></script> <script src="ms-its:diadem.chm::/variables.js"></script> <script src="ms-its:diadem.chm::/web.js" type="text/javascript" language="JavaScript1.2"></script> <script src="ms-its:diadem.chm::/Tools.js" type="text/javascript" language="JavaScript1.2"></script>
11-19-2014 03:35 AM
I am really sorry but I cannot make it work.
WHat should I do.
1. I copy the function in UserCmdReport.vbs
2. I produce my table
3. I change the format of the channel I want to color adding the function in the format : @@TabColorCol(CFV)@@
4. nothing happen or rather, the cell are fill up with "@@TabColorCol(CFV)@@"
To be honest I do not understand the input of the function TabColorCol(CFV)...
Thank you,
Best regards,
Louval
11-19-2014 08:45 AM
Did you register the command correctly? Its this menu
,
the functions in the script should change colors
and then you can use it in your report
.
11-19-2014 09:07 AM
Thank you,
Yes it is alright....
but it keeps giving error as :
1 4:05:24 PM Error:
2 Invalid variable access (D2TABCOL).
Parent object open?
3 4:05:24 PM Error:
4 Invalid variable access (D2TABCOL).
Parent object open?
5 4:05:25 PM Error:
Undefined variable in "D2TabCol" command.
6 4:05:25 PM Error:
7 Incorrect instruction or user command.
In <Table_color.VBS> (line: 12, column: 12):
Invalid variable access (D2TABCOL).
Parent object open?
8 4:05:25 PM Error:
9 Error message from DIAdem command kernel:
Wrong number of arguments or invalid assignment of properties: "TABCOLORCOL"
10 4:05:25 PM Error:
11 Invalid variable access (D2TABCOL).
Parent object open?
11-19-2014 04:58 PM - edited 11-19-2014 05:03 PM
Do you have a data channel assigned to the Table column? That is the only data type that will work. Variables and Text Lists won't work. Unfortunately, DIAdem is not Excel. It does not allow static table cell coloring for individual cells. You have to map a data channel to a table column in order for the User command approach to work.
Personally, I don't like this limitation, and have requested that control over table cell formatting be improved so that it can be accomplished without the need to assign a data channel to a column to control formatting.
See this thread:
It's old, but still applies.