Create a loop to display References Lines in a GraphHello 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 !!
Automation and ScriptingMass CustomizationQuality and Process EngineeringRe: Create a loop to display References Lines in a GraphHere'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 )} )
);
);
);Re: Create a loop to display References Lines in a GraphThank you Jim for your quick reply, really helpful !
Re: Create a loop to display References Lines in a GraphWelcome to the Discussion Community!
Here is one way of adding the reference lines

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 );
);