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

Use variable in graph builder customize script window

Hi

 

I would like to plot 3 lines and a shaded area between the outer lines using the customize script in graph builder.  The first is the line y0=x.  The second and third lines are y1= a*x and y2 = b*x.  (example a = 1.05 and b = 0.95 I want to shade between the lines y1 and y2.  I use a polygon fill to do this, but the polygon function requires fixed values and does not scale with the graph axes.  How can I make the shaded region scale with the graph as do the three lines? i.e. put a variable in the polygon function

 

jeffsecor_0-1658202661957.png

 

Pen Size( 4 );
Line Style( dashed );
Pen Color( "black" );
Y Function( x, x );
Pen Size( 4 );
Line Style( dashed );
Pen Color( "red" );
Y Function( 1.1 * x, x );
Pen Size( 4 );
Line Style( dashed );
Pen Color( "red" );
Y Function( .9 * x, x );
Transparency( 0.5 );
Fill Color( {0.38, 0.84, 0.67} );
Polygon( [0.05, 1, 1, .05], [.045, .95, 1.05, .055] );

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Use variable in graph builder customize script window

Here is a simple example of how you can change the polygon to match the axis settings.

txnelson_0-1658206272327.png

txnelson_1-1658206312256.png

Names Default To Here( 1 );
dt = New Table( "Sample",
	Add Rows( 7 ),
	New Column( "Column 1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.65] )
	),
	New Column( "Column 2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [0.2, 0.3, 0.25, 0.3, 0.55, 0.68, 0.9] )
	)
);

gb = Graph Builder(
	Size( 528, 454 ),
	Show Control Panel( 0 ),
	Variables( X( :Column 1 ), Y( :Column 2 ) ),
	Elements( Points( X, Y, Legend( 5 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Column 1",
			ScaleBox,
			{Min( -0.0389121338912134 ), Max( 1.21814306472226 ), Inc( 0.2 ), Minor Ticks( 1 ),
			Label Row(
				{Major Grid Line Color( 1 ), Minor Grid Line Color( 1 ), Show Major Grid( 1 ),
				Show Minor Grid( 1 )}
			)}
		),
		Dispatch(
			{},
			"Column 2",
			ScaleBox,
			{Min( -0.05302734375 ), Max( 1.20978927612305 ), Inc( 0.2 ), Minor Ticks( 2 ),
			Label Row(
				{Major Grid Line Color( 1 ), Minor Grid Line Color( 1 ), Show Major Grid( 1 ),
				Show Minor Grid( 1 )}
			)}
		)
	)
);

Report( gb )[FrameBox( 1 )] << Add Graphics Script(
	Pen Size( 4 );
	Line Style( dashed );
	Pen Color( "black" );
	Y Function( x, x );
	Pen Size( 4 );
	Line Style( dashed );
	Pen Color( "red" );
	Y Function( 1.1 * x, x );
	Pen Size( 4 );
	Line Style( dashed );
	Pen Color( "red" );
	Y Function( .9 * x, x );
	Transparency( 0.5 );
	Fill Color( {0.38, 0.84, 0.67} );
	xMat = [0.05];
	yMat = [.045];
	xMax = Report( gb )[AxisBox( 2 )] << get max;
	xMat = xMat || xMax || xMax || [0.045];
	yMat = yMat || xMax * 1.1 || xMax * .9 || [0.055];
	Polygon( xMat, yMat );
);

 

Jim

View solution in original post

jeffsecor
Level I

Re: Use variable in graph builder customize script window

Thanks, I adapted this a bit and included Col Max (Column 2)  as the upper limit so this all goes into the smaller script environment of script builder without having to define an entire graph builder script.  Thanks for the help

Pen Size( 4 );
Line Style( dashed );
Pen Color( "black" );
Y Function( x, x );
Pen Size( 4 );
Line Style( dashed );
Pen Color( "red" );
Y Function( 1.1 * x, x );
Pen Size( 4 );
Line Style( dashed );
Pen Color( "red" );
Y Function( .9 * x, x );
Transparency( 0.5 );
Fill Color( {0.38, 0.84, 0.67} );
xMat = [0];
yMat = [0];
xMax = 2*Col Max (Column 1);
yMax = 2*Col Max (Column 2);
xMat = xMat || xMax || xMax || [0];
yMat = yMat || xMax * 1.1 || xMax * .9 || [0];
Polygon( xMat, yMat );

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Use variable in graph builder customize script window

Here is a simple example of how you can change the polygon to match the axis settings.

txnelson_0-1658206272327.png

txnelson_1-1658206312256.png

Names Default To Here( 1 );
dt = New Table( "Sample",
	Add Rows( 7 ),
	New Column( "Column 1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.65] )
	),
	New Column( "Column 2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [0.2, 0.3, 0.25, 0.3, 0.55, 0.68, 0.9] )
	)
);

gb = Graph Builder(
	Size( 528, 454 ),
	Show Control Panel( 0 ),
	Variables( X( :Column 1 ), Y( :Column 2 ) ),
	Elements( Points( X, Y, Legend( 5 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Column 1",
			ScaleBox,
			{Min( -0.0389121338912134 ), Max( 1.21814306472226 ), Inc( 0.2 ), Minor Ticks( 1 ),
			Label Row(
				{Major Grid Line Color( 1 ), Minor Grid Line Color( 1 ), Show Major Grid( 1 ),
				Show Minor Grid( 1 )}
			)}
		),
		Dispatch(
			{},
			"Column 2",
			ScaleBox,
			{Min( -0.05302734375 ), Max( 1.20978927612305 ), Inc( 0.2 ), Minor Ticks( 2 ),
			Label Row(
				{Major Grid Line Color( 1 ), Minor Grid Line Color( 1 ), Show Major Grid( 1 ),
				Show Minor Grid( 1 )}
			)}
		)
	)
);

Report( gb )[FrameBox( 1 )] << Add Graphics Script(
	Pen Size( 4 );
	Line Style( dashed );
	Pen Color( "black" );
	Y Function( x, x );
	Pen Size( 4 );
	Line Style( dashed );
	Pen Color( "red" );
	Y Function( 1.1 * x, x );
	Pen Size( 4 );
	Line Style( dashed );
	Pen Color( "red" );
	Y Function( .9 * x, x );
	Transparency( 0.5 );
	Fill Color( {0.38, 0.84, 0.67} );
	xMat = [0.05];
	yMat = [.045];
	xMax = Report( gb )[AxisBox( 2 )] << get max;
	xMat = xMat || xMax || xMax || [0.045];
	yMat = yMat || xMax * 1.1 || xMax * .9 || [0.055];
	Polygon( xMat, yMat );
);

 

Jim
jeffsecor
Level I

Re: Use variable in graph builder customize script window

Thanks, I adapted this a bit and included Col Max (Column 2)  as the upper limit so this all goes into the smaller script environment of script builder without having to define an entire graph builder script.  Thanks for the help

Pen Size( 4 );
Line Style( dashed );
Pen Color( "black" );
Y Function( x, x );
Pen Size( 4 );
Line Style( dashed );
Pen Color( "red" );
Y Function( 1.1 * x, x );
Pen Size( 4 );
Line Style( dashed );
Pen Color( "red" );
Y Function( .9 * x, x );
Transparency( 0.5 );
Fill Color( {0.38, 0.84, 0.67} );
xMat = [0];
yMat = [0];
xMax = 2*Col Max (Column 1);
yMax = 2*Col Max (Column 2);
xMat = xMat || xMax || xMax || [0];
yMat = yMat || xMax * 1.1 || xMax * .9 || [0];
Polygon( xMat, yMat );