LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change background color of a table based on table cell values quickly.

Is there a more effecient way to change the background color of a table based on the cell values of the table?

 

I can do this cell-by-cell using the property node, but it is very slow. It helps a little by deferring panel update, but it is still slow. Is there a better way? 

 

Thanks.

 

Ian

 

0 Kudos
Message 1 of 19
(6,424 Views)

Example_VI_BD.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 19
(6,419 Views)

Jim Thank you for your help. This is what I am doing now, but it can be really slow if I have to color a large table, say, a 500 x 500 table. The speed is significantly increased when I "defer panel update". My real question is, instead of replacing an element of a 2D array representing the background color of a particular cell of a table, is there a way to update a 2D array representing the background color of the table at once? Thanks. Ian

0 Kudos
Message 3 of 19
(6,377 Views)

Hey Ian,

 

Jim's code may look similar to what you're currently doing, but it actually does do what you're looking for. The -2, -2 constant wired into the active cell actually means that the whole table is selected. So by wiring that in as a constant, you can change the color of your whole table.

 

Here's some more information on that if that wasn't a very clear explanation.

 

http://digital.ni.com/public.nsf/allkb/B8700C12AC7CE927862569DD0063CB0A

 

Ty Prather
Technical Marketing Specialist
National Instruments
0 Kudos
Message 4 of 19
(6,365 Views)

If you want to color each cell according to the value, you need to do it one cell at a time and the above answers don't apply.

 

You can dramatically speed up things by defering front panel updates for the duration of the operation.

 

(sample code can be seen in the top picture here)

 

EDIT: I noticed you tried this already. Can you show us your code?

How many cells need to be colored on average?  If there are not that many, first write the background color using -2,-2, the only write the few cells to be colored, skipping the rest.

How big is the table? If it is much bigger than the table indicator, all you need is to color the visible parts whenever the data or the scroll position changes.

0 Kudos
Message 5 of 19
(6,344 Views)

One way to hack it is to set all cells to transparent background color, then put an array of color boxes behind it.  This would require that all cells be the same size and shape.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 19
(6,323 Views)

That's an excellent idea, I will try that.

 

But isn't the background color of a table stored in a 2D array? Looks like we just cannot access it.

 

Actually, in most applications, "defer panel update" is good enough. Just in a few cases, it is still a little bit slow.

0 Kudos
Message 7 of 19
(6,289 Views)

Thanks for all good suggestions.

 

In my application, the table size can vary greatly.

 

At the moment, I am updating every cell using 2 FOR loops, cell by cell. I will use -2,-2 to color the table to most common color first as suggested, and then modify only those cells that need to be changed.

 

The part of the wiring diagram is attached which shows how I implemented the "Defer panel update" function. It is quite simple.

 

 

0 Kudos
Message 8 of 19
(6,282 Views)

Here is the better way. I struggled with this for far too long 🙂

 

Do you want to display a number in each cell of an array or table and also independently change the background color of each cell?  The table must be scrollable and the index control must work properly. It must redraw quickly. Here is a solution that meets these requirements.

 

This method uses a cluster of a string and a color box. The string is transparent and is in front of the color box. Put this cluster in an array and wire it as shown in the diagram. This also works with numeric values.

 

To see it work, run the vi. You are not limited to two colors. With minor code change’s you can have all the colors you want.

 

I know of two other ways to do this but each has problems.

 

The first method is to use a table with a property node to set the background color using nested for loops. This is very slow, typically 1 second per refresh. Setting all colors to green and then only turning the active cells red reduces that by half but this is still slow. In addition it produces a confusing flicker.

 

The second method is to stack an array of transparent text on top of an array of color boxes. This is fast but the scrollbars and the index controls do not work properly.

Message 9 of 19
(5,898 Views)

Overlapping objects typically cause a UI redraw penalty.

Can you show us your benchmarks for the table colors?  (e.g. Did you disable front panel updates when doing the table colors? Were the fields the same size?)

 

Why do you have so many FOR loops? Everything can be done in the first stack, right?

 

What happened to your diagram background?

Why are your panels located outside the screen when no longer maximised and why are they maximised to begin with?

0 Kudos
Message 10 of 19
(5,892 Views)