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

Automate Reference Line Based on Column Data

Hello, I am very new to JSL and am struggling to think of a way to automatically create multiple reference lines in a graph based on values in a specific column. Currently, I am graphing one variable (:Signal) on the Y axis, and three variables (:Zone, :Target, and :Condition) on the X axis. Each (:Target) variable has a specific (:historical signal) and I would like to find a way to automatically graph a (:Target)'s (:historical signal) as a reference line. The code I have is done by manually adding the historical signal value via h line(), but ideally the script would add a reference line for each (:target) based on its corresponding historical signal. Thank you!

Variability Chart(
	Y( :Signal ),
	X( :Zone, :Target, :Condition ),
	Analysis Type( "Choose best analysis (EMS REML Bayesian)" ),
	Show Range Bars( 0 ),
	Show Cell Means( 0 ),
	Std Dev Chart( 0 ),
	Mean Diamonds( 1 ),
	SendToReport(
		Dispatch(
			{"Variability Chart for Signal"},
			"Variability Chart",
			FrameBox,
			{Frame Size( 969, 240 ),
			Add Graphics Script(
				2,
				Description( "" ),
				Pen Color( "RED" );
				//Target 2
				H Line( 0, 2, 234 );
				//Target 3
				H Line( 2, 4, 670 );
				//Target 1
				H Line( 4, 6, 463 );
			)}
		)
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Automate Reference Line Based on Column Data

All that needs to be done, is to figure out how to get the values and the order, and then generate the required JSL.  Here is a simple example that should give you a start in the right direction to create your final script.

Names Default To Here( 1 );
dt = Current Data Table();

// Find the number of targets and get the means
Summarize( dt, targs = by( :Zone, :Target ), targMeans = Mean( :Historical Signal ) );

vc = Variability Chart(
	Y( :Signal ),
	X( :Zone, :Target, :Condition ),
	Analysis Type( "Choose best analysis (EMS REML Bayesian)" ),
	Show Range Bars( 0 ),
	Show Cell Means( 0 ),
	Std Dev Chart( 0 ),
	Mean Diamonds( 1 )
);

// Create the JSL to submit to generate the Target Lines
theExpr =
"Report( vc )[FrameBox( 1 )] << add graphics Script(
		Description( \!"\!" ),
		Pen Color( \!"RED\!" );";
For( ii = 1, ii <= N Items( targMeans ), ii++,
	theExpr = theExpr || "H Line( " || Char( (ii - 1) * 2 ) || "," || Char( (ii - 1) * 2 + 2 )
	 || "," || Char( targMeans[ii] ) || ");";
		
);
Eval( Parse( theExpr ) );
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Automate Reference Line Based on Column Data

Given your current data structure, here is one way of automating your Historical Signals

Names Default To Here( 1 );
dt = Current Data Table();
targ1 = Mean( :Historical Signal[dt << get rows where( :Target == "Target 1" )] );
targ2 = Mean( :Historical Signal[dt << get rows where( :Target == "Target 2" )] );
targ3 = Mean( :Historical Signal[dt << get rows where( :Target == "Target 3" )] );
Variability Chart(
	Y( :Signal ),
	X( :Zone, :Target, :Condition ),
	Analysis Type( "Choose best analysis (EMS REML Bayesian)" ),
	Show Range Bars( 0 ),
	Show Cell Means( 0 ),
	Std Dev Chart( 0 ),
	Mean Diamonds( 1 ),
	SendToReport(
		Dispatch(
			{"Variability Chart for Signal"},
			"Variability Chart",
			FrameBox,
			{Frame Size( 969, 240 ), Add Graphics Script(
				2,
				Description( "" ),
				Pen Color( "RED" );
				//Target 2
				H Line( 0, 2, targ2 );
				//Target 3
				H Line( 2, 4, targ3 );
				//Target 1
				H Line( 4, 6, targ1 );
			)}
		)
	)
);
Jim
mthacker477
Level I

Re: Automate Reference Line Based on Column Data

Hey txnelson, thank you so much for your response, this is almost exactly what I am looking for! The only other thing I am wondering is if it is possible to have the h line() code match with its corresponding :Target instead of having to manually enter the coordinates on the graph. In the future, I am going to be adding differing amounts of targets and they will not always be in the same order.

txnelson
Super User

Re: Automate Reference Line Based on Column Data

All that needs to be done, is to figure out how to get the values and the order, and then generate the required JSL.  Here is a simple example that should give you a start in the right direction to create your final script.

Names Default To Here( 1 );
dt = Current Data Table();

// Find the number of targets and get the means
Summarize( dt, targs = by( :Zone, :Target ), targMeans = Mean( :Historical Signal ) );

vc = Variability Chart(
	Y( :Signal ),
	X( :Zone, :Target, :Condition ),
	Analysis Type( "Choose best analysis (EMS REML Bayesian)" ),
	Show Range Bars( 0 ),
	Show Cell Means( 0 ),
	Std Dev Chart( 0 ),
	Mean Diamonds( 1 )
);

// Create the JSL to submit to generate the Target Lines
theExpr =
"Report( vc )[FrameBox( 1 )] << add graphics Script(
		Description( \!"\!" ),
		Pen Color( \!"RED\!" );";
For( ii = 1, ii <= N Items( targMeans ), ii++,
	theExpr = theExpr || "H Line( " || Char( (ii - 1) * 2 ) || "," || Char( (ii - 1) * 2 + 2 )
	 || "," || Char( targMeans[ii] ) || ");";
		
);
Eval( Parse( theExpr ) );
Jim