DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

diadem how to color cells individually

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

 

 

 

0 Kudos
Message 1 of 25
(10,470 Views)

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.

 

 

 

0 Kudos
Message 2 of 25
(10,466 Views)

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

 

0 Kudos
Message 3 of 25
(10,443 Views)

Hi louval

In DIAdem 2014 you can also set the color of individual cells. You can find an eplanation here:

http://zone.ni.com/reference/en-XX/help/370858K-01/reportapi/events/report_event_ondrawingcell_irept...

 

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

0 Kudos
Message 4 of 25
(10,431 Views)

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

 

 

0 Kudos
Message 5 of 25
(10,409 Views)

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>

0 Kudos
Message 6 of 25
(10,398 Views)

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

 

Download All
0 Kudos
Message 7 of 25
(10,390 Views)

Did you register the command correctly? Its this menu

UserCmd,

the functions in the script should change colors

 

 

ScriptChange 

and then you can use it in your report

 

 

Report.

0 Kudos
Message 8 of 25
(10,375 Views)

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?

 

 

 

0 Kudos
Message 9 of 25
(10,373 Views)

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:

https://forums.ni.com/t5/DIAdem-Idea-Exchange/Add-conditional-formatting-for-VIEW-and-REPORT-tables/...

It's old, but still applies.

 

 

 

0 Kudos
Message 10 of 25
(10,355 Views)