cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
EMJohnson-Kueny
Level III

Automate a reference line

As a way to learn JMP and a bit of JSL, I've been keeping track of Covid rates in my state. On a graph with new cases on the y and date on the x, I add a reference line at today's number of new cases as a sort of "we are here." Is there a way to automate this? I can tell that the "12601" and "12381" are the ones that need to change, but I don't know how to tell it to use the most recent values of "New Cases" (red) and "New Cases Rolling Average"(black).

Graph Builder(
	Size( 1245, 660 ),
	Show Control Panel( 0 ),
	Fit to Window( "Maintain Aspect Ratio" ),
	Variables(
		X( :Date ),
		Y( :New Cases ),
		Y( :New Case Rolling Average, Position( 1 ) ),
		Color( :Month )
	),
	Elements(
		Line( X, Y( 1 ), Y( 2 ), Legend( 5 ) ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 6 ) )
	),
	SendToReport(
		Dispatch(
			{},
			"New Cases",
			ScaleBox,
			{Min( -245.726960373999 ), Max( 19090.397676905 ), Inc( 2000 ),
			Minor Ticks( 1 ), Add Ref Line( 0, "Solid", "Black", "", 1 ),
			Add Ref Line( 12601, "Solid", "Red", "", 1 ),
			Add Ref Line( 12381, "Solid", "Black", "", 1 )}
		)
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Automate a reference line

Here is a modification of your script, that sets reference lines for the values of New Cases and New Case Rolling Average based upon the last row's values.  This is assuming that the last row in the data table has the latest values.

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

gb = dt << Graph Builder(
	Size( 1245, 660 ),
	Show Control Panel( 0 ),
	Fit to Window( "Maintain Aspect Ratio" ),
	Variables(
		X( :Date ),
		Y( :New Cases ),
		Y( :New Case Rolling Average, Position( 1 ) ),
		Color( :Month )
	),
	Elements(
		Line( X, Y( 1 ), Y( 2 ), Legend( 5 ) ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 6 ) )
	),
	SendToReport(
		Dispatch(
			{},
			"New Cases",
			ScaleBox,
			{Minor Ticks( 1 ), Add Ref Line( 0, "Solid", "Black", "", 1 )}
		)
	)
);

gbrpt = gb << report;
gbrpt[AxisBox( 2 )] << add ref line(
	dt:New Cases[N Rows( dt )],
	"Solid",
	"Red",
	"",
	1
);
gbrpt[AxisBox( 2 )] << add ref line(
	dt:New Case Rolling Average[N Rows( dt )],
	"Solid",
	"Black",
	"",
	1
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Automate a reference line

Here is a modification of your script, that sets reference lines for the values of New Cases and New Case Rolling Average based upon the last row's values.  This is assuming that the last row in the data table has the latest values.

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

gb = dt << Graph Builder(
	Size( 1245, 660 ),
	Show Control Panel( 0 ),
	Fit to Window( "Maintain Aspect Ratio" ),
	Variables(
		X( :Date ),
		Y( :New Cases ),
		Y( :New Case Rolling Average, Position( 1 ) ),
		Color( :Month )
	),
	Elements(
		Line( X, Y( 1 ), Y( 2 ), Legend( 5 ) ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 6 ) )
	),
	SendToReport(
		Dispatch(
			{},
			"New Cases",
			ScaleBox,
			{Minor Ticks( 1 ), Add Ref Line( 0, "Solid", "Black", "", 1 )}
		)
	)
);

gbrpt = gb << report;
gbrpt[AxisBox( 2 )] << add ref line(
	dt:New Cases[N Rows( dt )],
	"Solid",
	"Red",
	"",
	1
);
gbrpt[AxisBox( 2 )] << add ref line(
	dt:New Case Rolling Average[N Rows( dt )],
	"Solid",
	"Black",
	"",
	1
);
Jim
EMJohnson-Kueny
Level III

Re: Automate a reference line

Thank you very much, that helps a lot and yes I am adding to the bottom of the table.