<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Create a loop to display References Lines in a Graph in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/463590#M70825</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using JMP15 since 1 year but I am just beginning to get interesting in scripts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to write a script to display References Lines in a graph, based on a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Those tables are attached to my post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current script, displaying one reference line based on the first element of table dates, column date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 )} ) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to create a "For" loop to create automatically reference lines for each value of the table "dates".&lt;/P&gt;&lt;P&gt;Here is what I tried :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;= N row( dates), i++,
f = dates [ i ];
Add Ref Line( f, "Dotted", "Blue", "", 2 )
);
}) 
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when I run the script, no reference line appears.&lt;/P&gt;&lt;P&gt;How can I solve this issue ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Last question : if I do not add "Page(:cat)" in the graph variables, no reference line appears...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Jun 2023 11:22:08 GMT</pubDate>
    <dc:creator>elisexx</dc:creator>
    <dc:date>2023-06-11T11:22:08Z</dc:date>
    <item>
      <title>Create a loop to display References Lines in a Graph</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/463590#M70825</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using JMP15 since 1 year but I am just beginning to get interesting in scripts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to write a script to display References Lines in a graph, based on a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Those tables are attached to my post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current script, displaying one reference line based on the first element of table dates, column date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 )} ) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to create a "For" loop to create automatically reference lines for each value of the table "dates".&lt;/P&gt;&lt;P&gt;Here is what I tried :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;= N row( dates), i++,
f = dates [ i ];
Add Ref Line( f, "Dotted", "Blue", "", 2 )
);
}) 
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But when I run the script, no reference line appears.&lt;/P&gt;&lt;P&gt;How can I solve this issue ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Last question : if I do not add "Page(:cat)" in the graph variables, no reference line appears...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help !!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 11:22:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/463590#M70825</guid>
      <dc:creator>elisexx</dc:creator>
      <dc:date>2023-06-11T11:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a loop to display References Lines in a Graph</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/463655#M70826</link>
      <description>&lt;P&gt;Welcome to the Discussion Community!&lt;/P&gt;
&lt;P&gt;Here is one way of adding the reference lines&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1645655736438.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/40275i5C887D94371659EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1645655736438.png" alt="txnelson_0-1645655736438.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Documentation on how to use the Display Trees to manipulate the JMP output is found in the Scripting Index.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;= N Rows( dates ), i++,
	// Add for Cat = B
	(Report( gb )[axisbox( 1 )]) &amp;lt;&amp;lt; add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
	// Add for Cat = C
	(Report( gb )[axisbox( 3 )]) &amp;lt;&amp;lt; add ref line( dates:date[i], "Dotted", "Blue", "", 2 );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 22:38:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/463655#M70826</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-02-23T22:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create a loop to display References Lines in a Graph</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/464140#M70871</link>
      <description>&lt;P&gt;Thank you Jim for your quick reply, really helpful !&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 20:41:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/464140#M70871</guid>
      <dc:creator>elisexx</dc:creator>
      <dc:date>2022-02-24T20:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create a loop to display References Lines in a Graph</title>
      <link>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/464302#M70885</link>
      <description>&lt;P&gt;Here's a solution that doesn't use display trees.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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 &amp;lt;&amp;lt; 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 &amp;lt;= nitems(cat_unique), c++,
	scbox = c + 1;
	for (i = 1, i &amp;lt;= nrows(dts), i++,
		ref = dts:date[i];
		gb &amp;lt;&amp;lt; SendToReport(
			Dispatch( {}, "time", ScaleBox( scbox ), {Add Ref Line( ref, "Dotted", "Red", "", 2 )} )
		);
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Feb 2022 13:05:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-a-loop-to-display-References-Lines-in-a-Graph/m-p/464302#M70885</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2022-02-25T13:05:23Z</dc:date>
    </item>
  </channel>
</rss>

