cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
avner8943
Level I

Add Graphics Script H line with variable

Hi all,

I'm trying to add a horizontal line to graph builder object with variable, in this way its works

	x =  139.4;
	Show( x );   //x = 139.4;
	gbReport[Framebox( 1 )] << addGraphicsScript(

		H Line( x )
	);
	

 

But if I'm doing something like that

 

TR1_row = dt_lims << get selected rows;

TR1 = Column( dt_lims, "CL" )[TR1_row] ;

gbReport[Framebox( 1 )] << addGraphicsScript(
	
		H Line(TR1 )
	);  

It's not working, any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: Add Graphics Script H line with variable

@avner8943 ,

 

Attached is a script that uses a RowState Handler to change limits.

Names Default to Here(1);

dt = Open("$Sample_Data/Big Class.jmp");
dt << sort(By(:sex, :age), Replace Table(1));
dt << New Column( "Order", Numeric);
dt:Order << Set Each Value( If( row()==1 | :sex != lag(:sex,1), 1, lag(:Order,1) +1)) ; 
dtsum = dt << Summary( Group(:sex), Min(:height), mean(:height), Max(:height));

dtlims = dtsum << Stack(
	columns(
		:Name( "Min(height)" ),
		:Name( "Mean(height)" ),
		:Name( "Max(height)" )
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Limits" )
);

Close(NoSave, dtsum);
f= Function({a}, {TR1, i},
	print(a, fb);
//	show(a, fb);
    for(i=1, i<=nitems(fb), i++,
    	Try( fb[i] << Remove Graphics Script (1) )
    );
    TR1 = :Limits[dtlims << get selected rows];
    Eval (EvalExpr( fb << Add Graphics Script( H Line( Expr( TR1) ) ) ) );	
);


gb = dt << Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :Order ), Y( :height ), Group X(:sex) ),
	Elements( Points( X, Y, Legend( 3 ) ), Line( X, Y, Legend( 5 ) ) )
);

fb = gb << Xpath("//FrameBox");

rs = dtlims <<  Make RowState Handler(f );

Select one or multiple rows or clear all row selections and see the changes on all frameboxes.

 

image.png

 

This script was tested on JMP 14 & 15. Attached is slight modification of the script at line 26 so that the script works on JMP 13.

 

So there must be something else wrong with your script, because this works woth a RowState Handler script. 

View solution in original post

5 REPLIES 5
gzmorgan0
Super User (Alumni)

Re: Add Graphics Script H line with variable

@avner8943 ,

 

The syntax for H Line() is H Line(y),  H Line( x1, x2, y). Also, if you have a vector of values, try this script.

Names Default To Here( 1 );
v = [10, 50, 20];
New Window( "Example",
	Graph Box(
		Pen Size( 2 );
		H Line( v );
	)
);

Produces this plot:

 

image.png

Check if this script works for you.  If it doesn't, please specify which version of JMP and OS you are using.

avner8943
Level I

Re: Add Graphics Script H line with variable

This is working but how can I adjust this to my script that takes value from a specific cell in JMP table.
gzmorgan0
Super User (Alumni)

Re: Add Graphics Script H line with variable

@avner8943,

 

Here is a script that uses JMP sample data table Big Class and selectively uses only Males and adds 3 limits at once.   

 

Names Default to Here(1);

dt = Open("$Sample_Data/Big Class.jmp");
dt << sort(By(:sex, :age), Replace Table(1));
dt << New Column( "Order", Numeric);
dt:Order << Set Each Value( If( row()==1 | :sex != lag(:sex,1), 1, lag(:Order,1) +1)) ; 
dtsum = dt << Summary( Group(:sex), Min(:height), mean(:height), Max(:height));

dtlims = dtsum << Stack(
	columns(
		:Name( "Min(height)" ),
		:Name( "Mean(height)" ),
		:Name( "Max(height)" )
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Limits" )
);

Close(NoSave, dtsum);

TR1_row = dtlims << get rows where( :sex =="M");

TR1 = column(dtlims, "Limits")[TR1_row];

gb = dt << Graph Builder( where (:sex=="M"),
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :Order ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ), Line( X, Y, Legend( 5 ) ) )
);

gbreport = report(gb);

gbreport[FrameBox(1)] << Add Graphics Script( HLine( TR1 ) );

It produces this plot.

image.png

 

 

Not sure what seems to be the issue, unless there are no selected rows.

 

Good Luck!

 

avner8943
Level I

Re: Add Graphics Script H line with variable

Maybe because I do it inside a function and call this function from MakeRowStateHandler, when I try it outside the function it is working.

gzmorgan0
Super User (Alumni)

Re: Add Graphics Script H line with variable

@avner8943 ,

 

Attached is a script that uses a RowState Handler to change limits.

Names Default to Here(1);

dt = Open("$Sample_Data/Big Class.jmp");
dt << sort(By(:sex, :age), Replace Table(1));
dt << New Column( "Order", Numeric);
dt:Order << Set Each Value( If( row()==1 | :sex != lag(:sex,1), 1, lag(:Order,1) +1)) ; 
dtsum = dt << Summary( Group(:sex), Min(:height), mean(:height), Max(:height));

dtlims = dtsum << Stack(
	columns(
		:Name( "Min(height)" ),
		:Name( "Mean(height)" ),
		:Name( "Max(height)" )
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Limits" )
);

Close(NoSave, dtsum);
f= Function({a}, {TR1, i},
	print(a, fb);
//	show(a, fb);
    for(i=1, i<=nitems(fb), i++,
    	Try( fb[i] << Remove Graphics Script (1) )
    );
    TR1 = :Limits[dtlims << get selected rows];
    Eval (EvalExpr( fb << Add Graphics Script( H Line( Expr( TR1) ) ) ) );	
);


gb = dt << Graph Builder(
	Size( 528, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :Order ), Y( :height ), Group X(:sex) ),
	Elements( Points( X, Y, Legend( 3 ) ), Line( X, Y, Legend( 5 ) ) )
);

fb = gb << Xpath("//FrameBox");

rs = dtlims <<  Make RowState Handler(f );

Select one or multiple rows or clear all row selections and see the changes on all frameboxes.

 

image.png

 

This script was tested on JMP 14 & 15. Attached is slight modification of the script at line 26 so that the script works on JMP 13.

 

So there must be something else wrong with your script, because this works woth a RowState Handler script.