cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
scottahindle
Level IV

How to change legend names in JSL (in Graph Builder)?

I get a lot of data in a CSV file (many columns, many rows) and am working on a basic template in JSL to standardise the generation of graphs. (Rescaling the axes, renaming the axes, standardising the colour of the lines etc...) On the average I can get one CSV file per day so I want to put the data into a JMP Data table, run the script and have the graph output all automated.

My JMP file has by default the tag names as column headers which are not at all informative as a graph legend. One way around might be to rename all the columns but I would prefer to keep the tag names and therefore directly manipulate the text in the Legend Settings. (But done with JSL, not manually.)

I can easily access the legend box, for example:

 gbR = gb << Report; // gbR << Show Tree Structure;
s = gbR[legendbox(1)];
s << Set Title("new title");

In the attached PNG you see the idea.

Where I am now stuck is how to access the text in the legend box (except for the title) so I can manipulate it and change it using JSL.

I see that the script generated by graph builder speaks of "Legend model" and "Level name" but I've no success in the numerous things I've tried.

Any guidance on this would be most appreciated.

As said, using JSL, how to access the legend text to change it from its default?

Thanks.

 

 

9 REPLIES 9
txnelson
Super User

Re: How to change legend names in JSL (in Graph Builder)?

The details in the Scripting Index for a Legend Box() shows no message that allows for the changing of the actual labels in a legend. However, since the values in the legend are coming directly from the values in the data table, you can simply either change/recode the values in the data table or set the "Value Labels" column property.
Jim
scottahindle
Level IV

Re: How to change legend names in JSL (in Graph Builder)?

Thanks for confirming I haven’t missed something that is obvious.

Unfortunately, I don’t see (or am not able to see) how “Value Labels” can do what I am looking to achieve. My aim, to some extent or other, is to effectively modify the column name, not to manipulate the data values that are found in the rows below the column title.

If I make a simple table with a few values in the text in the legend changes if I use "Set Name" for a given column, for example “Column(dt, 1) << Set Name("New name");” This one line of syntax results in the text for column 1’s data updating and becoming “New name”.

The graph of my actual data has legend texts of the type “Mean(…Tag Name…)”. If use << Set Name with my actual data I still have a problematic legend text because it includes “Mean(… column name …)”.

Any idea on how to manipulate the legend text for a given column would be great to know. Perhaps I just make a legend from scratch so all properties in such a "self-made" legend are accessible and manipulable. I would like it be something scripted and not something required manual attention each time I make a new graph (probably daily).

Re: How to change legend names in JSL (in Graph Builder)?

Would it be possible to do something like this in your graph builder scripts:

 

Graph Builder(
	Variables( X( :age ), Y( :height ), Y( :weight, Position( 1 ) ) ),
	Elements( Line( X, Y( 1 ), Y( 2 ), Legend( 4 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				4,
				Level Name( 0, "abcd", Item ID( "Mean(height)", 1 ) ),
				Level Name( 1, "efgh", Item ID( "Mean(weight)", 1 ) )
			)}
		),
		Dispatch( {}, "400", LegendBox, {Set Title( "My Title" )} )
	)
);
scottahindle
Level IV

Re: How to change legend names in JSL (in Graph Builder)?

Thanks. Yes, certainly possible. I guess I would need a variable to capture the desired name for the legend text since I have different graphs in mind?

For example, as per example Graph Builder syntax:

 

_Legend1 = "abcd";
_Legend2 = "efgh";

If so, would I need to use the below to manage the use of a variable?

	Eval(
		Substitute(
			Expr(

Finally, is this option likely the only way to achieve a more "direct" manipulation of the legend text?

 

Re: How to change legend names in JSL (in Graph Builder)?

This is another possibility:

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
	Variables( X( :age ), Y( :height ), Y( :weight, Position( 1 ) ) ),
	Elements( Line( X, Y( 1 ), Y( 2 ), Legend( 4 ) ) )
);

lgnd = gb << Get Legend Display;
item1 = lgnd << Get Item( 4, 1 );
item1 << Set Label("Line 1");
item2 = lgnd << Get Item( 4, 2 );
item2 << Set Label("Line 2");

The first number in Get Item is the value from the Legend parameter in Graph Builder. The second number is going to be the index into that legend. It can be tricky to get these number right sometimes because we don't always show all the legends. If you want to see the complete list of legends go to the Legend Settings.

scottahindle
Level IV

Re: How to change legend names in JSL (in Graph Builder)?

Dear Paul,

In attached PNG you see the graph builder output I get running the syntax with and without

lgnd = gb << Get Legend Display;
item1 = lgnd << Get Item( 4, 1 );
item1 << Set Label("Line 1");
item2 = lgnd << Get Item( 4, 2 );
item2 << Set Label("Line 2");

I see no different in the text for the legend, I follow the logic of your syntax but don't see any effect from it.

In the second PNG you see what I was thinking I'd see after execution of your full syntax.

If you can still look into this and let me know a way I'd be very grateful. Thanks, Scott.

 

Re: How to change legend names in JSL (in Graph Builder)?

I'm sorry. That is a new feature in JMP 16. I didn't realize it had just been added and wasn't available in JMP 15. You will have to try the first method until JMP 16 is available. Again, I apologize for the misinformation.

Re: How to change legend names in JSL (in Graph Builder)?

I think you need to do this exactly that way (using expressions) if you want to do it with scripting. You may want to save the script of the graph, parse for the level name input between the brackets and extract as well substitue these. Then repopulate/rerun the modified script. This way you will be able to have a very general script which reacts on what is there to be changed rather than manually define for each scenario each time. However, it is more work to do.
It seems that the legend properties available do not have the text as property:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = dt << Graph Builder(
	Variables( X( :age ), Y( :height ), Y( :weight, Position( 1 ) ) ),
	Elements( Line( X, Y( 1 ), Y( 2 ), Legend( 4 ) ) )
);


r = Report( gb )[LegendBox( 1 )]; 
r << get properties();

/*
["Background Color" => 2147483647,
"Border" => {Left( 0 ), Top( 0 ), Right( 0 ), Bottom( 0 )}, "Enabled" => 1,
"Horizontal Alignment" => "Default",
"Margin" => {Left( 0 ), Top( 0 ), Right( 0 ), Bottom( 0 )}, "Padding" => {Left( 0 ),
Top( 0 ), Right( 0 ), Bottom( 0 )}, "Text Color" => 2147483647,
"Vertical Alignment" => "Default",
"Visibility" => "Visible"]
*/

And if you use

 r << legend settings

you will get a window that blocks any action in JMP until you press ok/cancel button. Therefore you cannot access the inner part of that window. Another thing incresing my doubt that this is possible is that the tree structure of the legend still shows "Mean(...)" no matter if one has changed that manually or not. So it seems there is something hidden positioned on top of the initial label. Or any other reason ...

Please add a wish list  comment so changing the legend text is changeable with JSL. in addition you may want to send it to tech support as well (support@jmp.com). Please do not forget to explain why as this increases the chance to get a higher priority. Thanks

/****NeverStopLearning****/

Re: How to change legend names in JSL (in Graph Builder)?

May this brute force script from @txnelson might help you to do a similar thing for the level item text. The script in that thread talsk about not showing certain legent items, but you might use a similar strategy within the expression for the level items.

/****NeverStopLearning****/