Subscribe Bookmark RSS Feed

How can I create a JSL script for saving a graph to the data table.

ivan_j_moore

Community Trekker

Joined:

Nov 24, 2014

I have a scheduled script running daily which saves out a data table.

However I would like to include graphs which I can do manually and save to data table.

Is there away of putting this into the script ?

Any help appreciated.

9 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

You just need to use the New Script message.  Here is the simple example from:

    Help==>Scripting Index

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt << New Script(

       "New Script",

       Distribution( Column( :Height, :Weight ), By( :sex ) )

);

Jim
gzmorgan0

New Contributor

Joined:

Jul 25, 2016

From your request, it is difficult to determine if you are wanting to (1) use the JMP 12 feature to add the graphs as an expression column;  or (2) you would like to embed a journal file of graphs; or (3) add a script to generate the graphs.  Jim Nelson provided an example for #3.

The example code below uses the JMP sample data of SAT scores, creates a summary report of SAT Math and Verbal scores by State, and for each State embeds an Overlay trend plot in an expression column for the corresponding row, and makes the expression column a label.

It also includes using Graph Builder to provide an example usage of this table.  Hover over a State and see the trend plot. This is an example for #1. If you are looking for an example for #2, or something else, please provide more details.

dtraw = Open("$sample_data\SATByYear.jmp");

ovl = Overlay Plot(

       X( :Year ),

       Y( :SAT Verbal, :SAT Math ),

       Y Scale( Left, Right ),

       Connect Thru Missing( 1 ),

       By( :State ),

       SendToReport(

             Dispatch( {}, "Overlay Plot Graph", FrameBox, {Frame Size( 288, 158 )} ),

             Dispatch(

                    {},

                    "Overlay Plot Graph",

                    FrameBox( 2 ),

                    {Frame Size( 288, 158 )}

             )

       )

);

dtsumry = dtraw << Summary(

       Group( :State ),

       Mean( :SAT Verbal ),

       Mean( :SAT Math ),

       Freq( "None" ),

       Weight( "None" )

);

dtsumry << new Column("ByYearPic", Expression);

for(i=1, i<=nitems(ovl), i++,

  ttl = report(ovl[i])[OutlineBox(1)] << get title();

  report(ovl[i])[OutlineBox(1)] << set title(word(2,ttl, "=") || " Scores by Year");

  pic = ovl[i] <<get picture;

  column(dtsumry, "ByYearPic")[i] = pic;     

);

column(dtsumry, "ByYearPic")<<label(1);

ovl<< close window();

New window("View", VListBox(

       Graph Builder(

       Level Spacing Color( "Medium Light Gray" ),

       Graph Spacing( 6 ),

       Variables( Color( :Name( "Mean(SAT Verbal)" ) ), Shape( :State ) ),

       Elements( Map Shapes( Legend( 6 ) ) ),

       show control panel(0)

),

Graph Builder(

       Level Spacing Color( "Medium Light Gray" ),

       Graph Spacing( 6 ),

       Variables( Color( :Name( "Mean(SAT Math)" ) ), Shape( :State ) ),

       Elements( Map Shapes( Legend( 6 ) ) ),

       Show control panel(0)

)

  ));

ivan_j_moore

Community Trekker

Joined:

Nov 24, 2014

Sorry for making it not very clear what I am asking, I will try and go through this step by step here.

1) I have a scheduled script running daily which saves out a data table, no problems here.

2) In the data table, manually or using script I create a "graph",

   Then manually I can for that "graph" -  "Save the script to data table" which then saves the graph to the data table, then when the data table is saved and then opened again the script can be easily opened / Ran.

Question is can this be scripted before saving the data table and is the "New script" option the way of doing this ?

Hope this helps.

12392_Image.jpg

Phil_Brown

Super User

Joined:

Mar 20, 2012

You are correct, txnelson​'s example of New Script accomplishes just that. gzmorgan0​​ presents and interesting alternative to including graphs with datatables.

PDB
txnelson

Super User

Joined:

Jun 22, 2012

Yes, the New Script message/function is what you want to use.

If the graph that you want to produce is always the same graph, then all you have to do is to take the script that you are currently manually saving to the data table and to paste it into the "New Script" message.

Names Default To Here( 1 );

dt = Current Data Table();

dt << New Script(

       "<Give the Script whatever name you want>",

       <paste the script here>

);

If you are not sure on how to get the script that produces the graph, all you need to do is to right click on the red triangle located to the left of the script you saved to the data table, and then select "Edit".  You can copy from the window that displays the script.


Jim
ivan_j_moore

Community Trekker

Joined:

Nov 24, 2014

Hi Jim,

Thanks for the info

Here is what I am running now see below.

Problem, I don't see the graph, and / or it dosen't seem to show up in the same location as doing it manually, Could you help here.

Names Default To Here( 1 );

dt =  ("XFER_SPLIT");

<< New Script("Fit Y by X",

      Fit Group(

  Bivariate( Y( :MEDIAN BISN_RES ), X( :PDATETIME ) ),

  Oneway(

  Y( :MEDIAN BISN_RES ),

  X( :MACH ),

  Means and Std Dev( 1 ),

  Mean Error Bars( 1 ),

  Std Dev Lines( 1 ),

  X Axis Proportional( 0 ),

  Points Jittered( 1 )

  ),

  <<{Arrange in Rows( 2 )}

));

txnelson

Super User

Joined:

Jun 22, 2012

Your first 2 lines are incorrect.  They should be:

dt=data table("xfer_split");

dt << New Script("Fit Y by X",

I think these changes should create the script in the data table.  The running of the script will still require the individual to click on the red triangle next to the embedded script, and to select "Run Script"

Jim
ivan_j_moore

Community Trekker

Joined:

Nov 24, 2014

Hi Jim,

Thanks for this info, the script is now working perfect. I believe I was going what we call JMP blind.

I am new to this website but I would like to add this information is simply Priceless.

I can now save the data table on a daily basis for others and all they have to do is click on the red triangle which produces the same graph every time.

Thanks for now.

jenkins_macedo

Community Trekker

Joined:

Jul 13, 2015

Addition to what others have said, bear in mind that JMP Pro 12 has the capability of storing several tables, charts, graphs, etc to the Application Builder, which has the capability to automatically update each of every table, graph, charts, etc once launch assuming that these tables are scripted to a update tables.

Jenkins Macedo