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
BooBee
Level III

Can JSL be used to automate plotting of charts and adding of ref lines among others

Hi,

 

I plot Distribution charts on a regular basis. Some days I get just a few columns of data, some days quite a bit more.

 

Once the individual charts are generated, I will need to adjust their respective min/max Y axis for readability, and then add in a couple of reference lines (basically USL and LSL lines).  After a while, it gets tedious, especially there are a lot of columns of data.

 

I would like to see if there is any way of automating this process since the process itself is relatively straightforward and repeating. I'm thinking of JSL scripting can be the solution here (I'm very new to scripting).

This is what I would like the script to do:
1. Each column of data consists of 5 data points, with the 1st and 2nd row containing the USL and LSL respectively
2. The script should read all the columns of data 

3. Plot individual Distribution charts for all the data

4. Add in USL and LSL reference lines (can we set the line thickness and color here?)

5. Then change the Min of the Y axis to LSL-0.003 and Max of Y axis to USL to USL+0.003

 

Can JSL do the above?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

Short answer: JSL can do that.

-Jarmo

View solution in original post

12 REPLIES 12
jthi
Super User

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

Short answer: JSL can do that.

-Jarmo
txnelson
Super User

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

  1. Welcome to the Community 
  2. Yes a JMP script can easily perform the tasks you outlined.
  3. JMP will automatically display your USL and LSL values on each of the charts.  However, the data structure you have described is not a normal structure for JMP.  It is a fairly simple matter to add to a script the JSL to take the USL and LSL data and move it into the Spec Limits column property for each column and then delete the first 2 rows of your data.
  4. Your data description appears to indicate that you only have 3 data points for each column of data.  (5 data points minus the LSL and USL rows) and from that you chart Distribution charts.  Using JMP terminology, a Distribution Chart is a Histogram display.  Is this what you are specifying as the chart you need?  If so, how do you create this chart from 3 data points.
  5. Changing the axis min and max values is very easy, and can be added to ones script.
  6. My interpretation of what you described in your initial entry may be totally wrong.  It would be nice if you could provide a sample of the data you are using, and an illustration of the chart you need to have displayed.
  7. It is my suggestion that you take the time to go through the Discovering JMP document available under the Help pull down menu in JMP.
Jim
BooBee
Level III

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

Thanks for your reply.

 

For pt 4, I'm sorry I did not explain myself well. To be clear, there will be 7 rows of data in each column. The 1st row is the LSL and 2nd row is the USL. Rows 3 to 7 are the actual data.

 

For pt 6, here are my sample data and resulting charts:

 

BooBee_0-1699436603693.png

 

BooBee_1-1699436637406.png

For the chart in this example, 1st and 2 rows of data are plotted in as well, which I don't want it to. They are the LSL and USL respectively. What I do normally is that I don't include the LSL and USL in the data.

txnelson
Super User

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

Here is an example script that produces what you want

txnelson_0-1699451963240.png

Names Default To Here( 1 );

// Create the data table
// dt = open( "<path to the file that has the data>" );
// Here is the sample data table you provided
dt = New Table( "Example",
	Add Rows( 7 ),
	New Column( "Data1",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [9.5, 10.5, 10, 10.2, 9.7, 9.6, 10.4] )
	),
	New Column( "Data2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [4.5, 5.5, 5, 5.1, 5.2, 4.9, 4.7] )
	)
);

// Ge all of the numeric column's names
colNameList = dt << get column names( string, continuous );

//Take the data from rows 1 & 2 and create the Spec Limints column property
For Each( {col}, colNameList,
	Eval(
		Substitute(
				Expr(
					Column( dt, col ) << set property(
						"Spec Limits",
						{LSL( _LSL_ ), USL( _USL_ ), Show Limits( 1 )}
					)
				),
			Expr( _LSL_ ), As Column( dt, col )[1],
			Expr( _USL_ ), As Column( dt, col )[2]
		)
	)
);

// Exclude and Hide row 1 & 2 to eliminate them from Distributions
dt << Select rows( {1,2} );
dt << hide and exclude;

// Run the Distribution Platform, having the Spec Limits as 
// Column Properties, will insure the proper Min and Max for
// the Y axis
dt << Distribution( column( eval(colNameList) ));
Jim
BooBee
Level III

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

Oh wow.. I certainly didn't expect you to write the script - Thank You!

 

I saw the front portion of the script is about creating the example table of data I provided earlier. How do I modify it so that I can ask the script to point to an existing data table of my choosing (I suppose that's the .jmp file) and then run?

 

jthi
Super User

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

Opening the table: Scripting Guide > Data Tables > Get Started with Data Tables (use Open() )

Getting path from user selection Pick File() 

-Jarmo
BooBee
Level III

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

My thinking is I have to incorporate the another set of code you helped to answer from my other thread:

 

If( Is Missing( fn ),
	throw(), 
	// Else Open the selected file
	Open( fn )
);

I suppose after opening the file, I need to load it as a data table? Which means using the dt syntax?

jthi
Super User

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

You use Open() to open the datatable, open then returns a reference to the datatable (if it succeeds in opening the file) which was opened which is then stored to dt variable

dt  = Open("myfile.jmp");
-Jarmo
BooBee
Level III

Re: Can JSL be used to automate plotting of charts and adding of ref lines among others

I have modified the script shared earlier by one of the contributors (thank you) so that the user can choose which data file (.jmp) file to open:

Names Default To Here( 1 );

// Open a dialog to choose a .jmp file to open

// Get the filename of the .jmp file to open
dt = Pick File("Select a .jmp file to open", "", {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 0, "");

// If the user did not select a file, exit the script
If( Is Missing( dt ),
	Throw(), 
	// Else Open the selected file
	Open( dt )
);

// Get all of the numeric column's names
colNameList = dt << get column names( string, continuous );

// Take the data from rows 1 & 2 and create the Spec Limits column property
For Each( {col}, colNameList,
	Eval(
		Substitute(
				Expr(
					Column( dt, col ) << set property(
						"Spec Limits",
						{LSL( _LSL_ ), USL( _USL_ ), Show Limits( 1 )}
					)
				),
			Expr( _LSL_ ), As Column( dt, col )[1],
			Expr( _USL_ ), As Column( dt, col )[2]
		)
	)
);

// Exclude and Hide row 1 & 2 to eliminate them from Distributions
dt << Select rows( {1,2} );
dt << hide and exclude;

// Run the Distribution Platform
dt << Distribution( column( eval(colNameList) ));

When running the script, I ran into the following error:

Send Expects Scriptable Object in access or evaluation of 'Send' , dt <<  /*###*/get column names( string, continuous ) /*###*/

It seemed there is a problem with the dt << get columns names?