cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lala
Level VII

How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

For example, the name column of Big Class.jmp automatically sets the color gradient of the name based on the value of the height column
It is required to be done in script.

Thanks!

2023-10-18_9-58-29.png

16 REPLIES 16
lala
Level VII

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

EmEditor

2023-10-18_18-49-47.png

jthi
Super User

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

Lots of assumptions made in this script and it definitely isn't robust

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
m = 4;
Eval(
	Eval Expr(
		Column(dt, m) << set property(
			"Color Gradient",
			{"Green to White to Red", Range(
				{Expr(Col Min(Column(m))), Expr(Col Max(Column(m))), Expr(Col Mean(Column(m)))}
			)}
		) << Color Cell by Value(1);
	)
);

// Lots of assumptions made in this solution

str = (dt << get as report) << get html;
// get just <table> and drop first row (headers)
l = Words(Regex(str, "<table.*</table>"), "\!N");
Remove From(l, 1,2);
Remove From(l, N Items(l));

// Get bgcolors 
colors = {};
For Each({line}, l,
	str = Regex(line, "bgcolor=#(.*?)>", "\1");
	Insert Into(colors, str);
);

// Convert colors
// Option 1 (might work?)
jmp_colors = Transform Each({color}, colors, Hex To Number(color) * -1);

// Option 2
jmp_colors2 = Transform Each({color}, colors, 
	r = Hex To Number(Left(color, 2));
	g = Hex To Number(Substr(color, 3, 2));
	b = Hex To Number(Right(color, 2));
	RGB Color({r,g,b});
);

// Set colors

// One row at the time
For Each Row(
	:name << Color Cells(jmp_colors[Row()], Row());
);

// Or create list of lists and use that
color_list = Transform Each({jmp_color, idx}, jmp_colors2,
	Eval List({jmp_color, idx});
);
Eval(EvalExpr(:age << Color Cells(Expr(color_list))));
-Jarmo
lala
Level VII

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

be of no effect?

 

l = Words(Regex(str, ""), "\!N");
lala
Level VII

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

I used the sentence JSL didn't get it right, for some reason, JMP 17

Thanks!

 

 

 

str = (dt << get as report) << get html;
// get just  and drop first row (headers)
l = Words(Regex(str, ""), "\!N");
Remove From(l, 1,2);
Remove From(l, N Items(l));
jthi
Super User

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

Your regex pattern is incorrect

-Jarmo
lala
Level VII

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

 

Eval(EvalExpr(:age << Color Cells(Expr(color_list))));

How do I modify this JSL to be a loop?

Thank you for your help!

For( j = 1, j <= N Row( dt ), j++,
	dt[j, "age"] << color_list( {j} )//?
);

 

jthi
Super User

Re: How to use JSL to set the color gradient of a column in text format by the value of a numeric column?

You can get the idea from Transform Each I used or use the other method with For Each Row

-Jarmo