Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
Super User

## How do you get the color of a specific cell in a data table using JSL?

I have a script where I need to determine what color specific cells in a data table have been set to.  I can find messages that can be sent to specific cells to color them, but my searches have failed to see anyway to retrieve the color of specific cells.  Does anyone have a solution?

Jim
2 REPLIES 2
Highlighted
Super User

## Re: How do you get the color of a specific cell in a data table using JSL?

The cell colors seem to be stored in a hierarchical list but I, too, can't find an easy way to access them.

Try something like this:

//Example table

dt=New Table( "test",

New Column( "X",

Numeric,

Continuous,

Format( "Best", 12 ),

Color Cells( {{38, {1}}, {9, {2}}, {74, {3, 4}}} ),

Set Selected,

Set Values( [1, 2, 3, 4, 5] )

)

);

// Define function

get_cell_color = Function( {col, r},

s = col << get script;

//Locate argument "Color Cells" in column script

For( i = 1, i <= N Arg( s ), i++,

If( Head Name( Arg( s, i ) ) == "Color Cells",

p = i;

Break();

)

);

//Identify the sublist that contains the color of row r

L = Arg( Arg( s, p ), 1 );

For( i = 1, N Items( L ), i++,

If( N Row( Loc( L[i][2], r ) ) == 1,

color = L[i][1];

Break();

)

);

color;

);

// Run function to find color of row four in first column

cellcolor = get_cell_color( Column( 1 ), 4 );

// Confirm..

New Window( "color",

Spacer Box( size( 200, 100 ), color( cellcolor ) )

);

Highlighted
Super User

## Re: How do you get the color of a specific cell in a data table using JSL?

Thanks for the quick response. Function works well. I had to modify it a bit to handle the case where the all of the cells in a column have been set to the same color.

Jim Nelson,

Sent from Windows Mail

Jim
Article Labels

There are no labels assigned to this post.