cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
markschwab
Level IV

Using JSL to add reference lines to Page By graphs

I have a script where I use Page By to create a set of graphs. I want to add different reference lines to each graph, pulled from a list.

 

Currently the only way I know how to specify which graphs to add the reference lines to is by referring to the graph by its integer index (which seems to start at 2) using ScaleBox. (Please let me know if there's a better way than using the integer index.) E.g.:

 

For( i= 1, i<= n, i+=1,
	RefLineValue= RefLineList[i];
	mygraph << SendToReport(
		Dispatch(
			{},
			"Data",
			ScaleBox( i+1 ),
			{Add Ref Line( RefLineValue, "Solid", "Black", "", 1 )}
		);
	)
);

This almost works, but my issue is that I don't know how to get the integer index specified properly for the ScaleBox function. The Page By function seems to put the graphs into some kind of alphabetical order, so I thought if I use Sort List( RefLineList ) then the ordering of the list would match the ordering of the graphs.

 

But ordering doesn't quite match: E.g. if the variables in the Page By role are [A50, B50, B100] then the graphs will be ordered [A50, B50, B100] but the list created using Sort List will be ordered [A50, B100, B50].

 

Is there a way to specify the Page By graph by name instead of by integer index? And if not, is there a way to sort my list so the list order matches the graph order?

1 REPLY 1
txnelson
Super User

Re: Using JSL to add reference lines to Page By graphs

Graph Builder is using a hybrid sort.  Here is a little script that will do that for your list values

refList = {"B100", "A50", "B50"};
For( i = 1, i <= N Items( refList ), i++,
	If( Length( refList[i] ) < 4,
		refList[i] = Substr( refList[i], 1, 1 ) ||
		Substr( "00", Length( refList[i] ) - 1 ) ||
		Substr( refList[i], 2 )
	);

);
refList = Sort List( refList );

For( i = 1, i <= N Items( refList ), i++,
	While( Length( Word( 1, refList[i], "0" ) ) == 1,
		refList[i] = Substr( refList[i], 1, 1 ) ||
		Substr( refList[i], 3 )
	)
);

I also suggest that you take a look at using a simpler method in setting your reference lines.  If you go directly to the AxisBox that you want the reference line added to, it is done with simpler code.  Below is an example.  Also, the Scripting Guide has a complete section on working with Display Trees, and the Scripting Index has definitions and examples for all of the functions.

names default to here(1);
dt=open("$SAMPLE_DATA/big class.jmp");

refList = {60,65};

gb =  dt << Graph Builder(
	Size( 528, 956 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ), Page( :sex ) ),
	Elements( Points( X, Y, Legend( 8 ) ), Smoother( X, Y, Legend( 9 ) ) )
);
Summarize( dt, groups = by( :Sex ) );
For( i = 1, i <= N Items( groups ), i++,
	Report( gb )[axisbox( i * 2 )] << Add Ref Line(
		refList[i],
		"Solid",
		"Black",
		"",
		1
	)
);
Jim