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

Create a loop to display References Lines in a Graph

Hello all,

 

I am using JMP15 since 1 year but I am just beginning to get interesting in scripts.

 

I would like to write a script to display References Lines in a graph, based on a table.

 

I have 2 tables : data (on which I run the script, to plot value=f(time)) and dates, containing one column with dates corresponding to the references lines I would like to have in the graph.

Those tables are attached to my post.

 

Here is my current script, displaying one reference line based on the first element of table dates, column date.

 

ref1 = dates:name( "date" )[1]; 

Graph Builder(
	Variables( X( :time ), Y( :value ),Page(:cat) ),
	Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
	SendToReport( Dispatch( {}, "time", ScaleBox( 2 ), {Add Ref Line( ref1, "Dotted", "Red", "", 2 )} ) )
);

I would like to create a "For" loop to create automatically reference lines for each value of the table "dates".

Here is what I tried : 

 

ref1 = dates:name( "date" )[1]; 

Graph Builder(
	Variables( X( :time ), Y( :value ),Page(:cat) ),
	Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
	SendToReport( Dispatch( {}, "time", ScaleBox( 2 ), 
{
For( i = 1, i <= N row( dates), i++,
f = dates [ i ];
Add Ref Line( f, "Dotted", "Blue", "", 2 )
);
}) 
);

But when I run the script, no reference line appears.

How can I solve this issue ? 

 

 

Last question : if I do not add "Page(:cat)" in the graph variables, no reference line appears...

 

Thank you for your help !!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Create a loop to display References Lines in a Graph

Welcome to the Discussion Community!

Here is one way of adding the reference lines

txnelson_0-1645655736438.png

Documentation on how to use the Display Trees to manipulate the JMP output is found in the Scripting Index.

Names Default To Here( 1 );

dt = Data Table( "data" );
dates = Data Table( "dates" );
ref1 = dates:name( "date" )[1]; 

gb = Graph Builder(
	Variables( X( :time ), Y( :value ), Page( :cat ) ),
	Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
	SendToReport(
		Dispatch( {}, "time", ScaleBox( 2 ), {Add Ref Line( ref1, "Dotted", "Red", "", 2 )} )
	)
);
// Add reference lines
For( i = 1, i <= N Rows( dates ), i++,
	// Add for Cat = B
	(Report( gb )[axisbox( 1 )]) << add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
	// Add for Cat = C
	(Report( gb )[axisbox( 3 )]) << add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
);

 

Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Create a loop to display References Lines in a Graph

Welcome to the Discussion Community!

Here is one way of adding the reference lines

txnelson_0-1645655736438.png

Documentation on how to use the Display Trees to manipulate the JMP output is found in the Scripting Index.

Names Default To Here( 1 );

dt = Data Table( "data" );
dates = Data Table( "dates" );
ref1 = dates:name( "date" )[1]; 

gb = Graph Builder(
	Variables( X( :time ), Y( :value ), Page( :cat ) ),
	Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
	SendToReport(
		Dispatch( {}, "time", ScaleBox( 2 ), {Add Ref Line( ref1, "Dotted", "Red", "", 2 )} )
	)
);
// Add reference lines
For( i = 1, i <= N Rows( dates ), i++,
	// Add for Cat = B
	(Report( gb )[axisbox( 1 )]) << add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
	// Add for Cat = C
	(Report( gb )[axisbox( 3 )]) << add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
);

 

Jim
elisexx
Level I

Re: Create a loop to display References Lines in a Graph

Thank you Jim for your quick reply, really helpful !

pmroz
Super User

Re: Create a loop to display References Lines in a Graph

Here's a solution that doesn't use display trees. 

Names Default To Here( 1 );

dt  = Data Table( "data" );
dts = Data Table( "dates" );

// Get the unique values of cat
summarize(cat_unique = by(dt:cat));

gb = dt << Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :time ), Y( :value ), Page( :cat ) ),
	Elements( Points( X, Y, Legend( 4 ), Summary Statistic( "Mean" ) ) ),
);

// Add reference lines
for (c = 1, c <= nitems(cat_unique), c++,
	scbox = c + 1;
	for (i = 1, i <= nrows(dts), i++,
		ref = dts:date[i];
		gb << SendToReport(
			Dispatch( {}, "time", ScaleBox( scbox ), {Add Ref Line( ref, "Dotted", "Red", "", 2 )} )
		);
	);
);