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

Dynamic Reference Lines in Graph Builder

I am trying to (simply) create custom reference lines and areas in Graph Builder so when I use a local data filter the references dynamically adjust to the data being presented. In the attached there are two "Model Types" (A and B) and the saved script shows the reference areas for Model Type B. When you select "A" using the local data filter, the graph changes but, of course, the references (having been set manually using axis reference ranges) does not change.

 

I have tried adding columns to represent the ranges and pointing to those from the script you can add by right clicking the graph area. But these scripts (to my knowledge) don't allow pointing to a column. It seems a simple way would be to add a reference to the axis (per usual) but have a "dynamic" option that would let you script the reference lines (in the form of Y = mX + B, and of course curvilinear versions) or script reference ranges, with either option pointing to columns or able to calculate the line/range on the fly based on available data that may not be one of the graph variables but would be one of the table variables.

 

All help greatly appreciated. JMP support punted on this and suggested I post here.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Dynamic Reference Lines in Graph Builder

What I would suggest is adding new columns to your table and then using those in the graph. Usually this is most flexible option (in my opinion), if it fits your need, BUT it can be very annoying to build in graph builder.

With this method you can also view all your Model Types at the same time if needed by using X/YGroup (or Page)

jthi_2-1712896226696.pngjthi_3-1712896233478.png

I added new column for Mean, green top/bottom and yellow top/bottom (just some mean +/- sigma limits in my example)

jthi_4-1712896289245.png

 

Using Filter Change handler to set reference lines is other option or you could write graphic script which should be able to handle this but can be complicated to figure out.

 

 

 

-Jarmo

View solution in original post

3 REPLIES 3
hogi
Level XI

Re: Dynamic Reference Lines in Graph Builder

This can be done with a Filter Change handler:

dt = current data table();
gb = dt << Graph Builder(
	Size( 707, 814 ),
	Variables( X( :Date ), X( :Day of Week, Position( 1 ) ), Y( :FP Rate ) ),
	Elements(
		Line( X( 1 ), X( 2 ), Y, Legend( 4 ) ),
		Points( X( 1 ), X( 2 ), Y, Legend( 5 ) )
	)
);

ldf = gb <<	Local Data Filter(
		Add Filter( columns( :Model Type ), Where( :Model Type == "B" ) )
	);

f = function ({a},myrows =ldf << Get Filtered Rows;
	myData =dt [myrows, "FP Rate"];
	myMean = mean(myData);
	mystdDev = std dev (myData);
	y1 = myMean - 2 * mystdDev;
	y2 = myMean + 2 * mystdDev;
	
	// remove old ref lines
	Eval(Eval Expr(report(gb)[AxisBox(2)] <<Remove Ref Line( Expr(Eval List({0, y1 old})))));
	Eval(Eval Expr(report(gb)[AxisBox(2)] <<Remove Ref Line( Expr(Eval List({y1 old, y2 old})))));
	Eval(Eval Expr(report(gb)[AxisBox(2)] <<Remove Ref Line( Expr(Eval List({y2 old,1})))));

	// add new ref lines
	report(gb)[AxisBox(2)] << {Add Ref Line( {0, y1}, "Solid", "Light Yellow", "", 1, 0.25 ),
	Add Ref Line( {y1, y2}, "Solid", "Green", "", 1, 0.25 ),
	Add Ref Line( {y2, 1}, "Solid", "Light Yellow", "", 1, 0.25 )
	};
	
	y1 old = y1;
	y2 old = y2;
	
	
	
);

// gets trigger if user changes the selection 
	
x = ldf << Make Filter Change Handler(f);

txnelson
Super User

Re: Dynamic Reference Lines in Graph Builder

 

Jim
jthi
Super User

Re: Dynamic Reference Lines in Graph Builder

What I would suggest is adding new columns to your table and then using those in the graph. Usually this is most flexible option (in my opinion), if it fits your need, BUT it can be very annoying to build in graph builder.

With this method you can also view all your Model Types at the same time if needed by using X/YGroup (or Page)

jthi_2-1712896226696.pngjthi_3-1712896233478.png

I added new column for Mean, green top/bottom and yellow top/bottom (just some mean +/- sigma limits in my example)

jthi_4-1712896289245.png

 

Using Filter Change handler to set reference lines is other option or you could write graphic script which should be able to handle this but can be complicated to figure out.

 

 

 

-Jarmo