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****/