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.
ScriptingRe: 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.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" )} )
)
);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.
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.