Choose Language Hide Translation Bar
mt7575
New Contributor

JSL Stacked Bar graph for n number of columns

Hi,

I would like to script a stacked bar graph from a data table for which I don't know what the columns will be.

 

1. Has a data table created with required columns

2. Add a data filter to select the required rows and exclude the remaining

2. Should create a stacked bar graph from the available rows for each column after the first against the first column.

3. Don't know the column names and exact count except for the first column.

 

I have created a stacked bar graph for one set of data and looks like the following. 

 

I have copied the script from the graph builder and here it is how it looks.

 

Graph Builder(
Size( 500, 590 ),
Variables(
X( :BIBID ),
Y( :Name( "Row %(Fail, Column2)" ) ),
Y( :Name( "Row %(Fail, Column3)" ), Position( 1 ) ),
Y( :Name( "Row %(Fail, Column4)" ), Position( 1 ) ),
Y( :Name( "Row %(Fail, Column5)" ), Position( 1 ) ),
Y( :Name( "Row %(Fail, Column6)" ), Position( 1 ) ),
Y( :Name( "Row %(Fail, Column7)" ), Position( 1 ) ),
Y( :Name( "Row %(Fail, Column8)" ), Position( 1 ) )
),
Elements(
Bar(
X,
Y( 1 ),
Y( 2 ),
Y( 3 ),
Y( 4 ),
Y( 5 ),
Y( 6 ),
Y( 7 ),
Legend( 4 ),
Bar Style( "Stacked" )
)
)
);

 

My question is how to parameterize the Variables (Y) and Elements (Y) under Graph Builder through JSL?

PassFailBin.jpgPass Fail Bin

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User

Re: JSL Stacked Bar graph for n number of columns

@mt7575, when writing a script there are many questions that need to be answered; for example, is this expected to be an interactive display or create a graph and save it as a png? to a journal? to PPTX? You did not mention which verison of JMP you are using, which OS you have (there are some differences in MAC and Windows syntax), nor the level of your JSL skills. When teaching or writing about JSL or any scripting language, the best way to be effective is to "know your tools" which is another way of saying you need to have some basic skiils to write or even maintain a script someone else writes for you. 

Attached is a script written for an interactive display to select which items in X, and which Y's to plot.  It uses the following JSL "tools". For each item listed that you have not scripted, you should spend time in Help > Scripting Index,  exploring the scripts, options and messages. 

  •  Display boxes: FilterColSelector, ButtonBox, HListBox, VListBox, PanelBox, GraphBuilderBox
  • Objects: GraphBuilder, DataFilter, Expressions, Data Table

Not knowing your JSL skill, a Go button with an attached expression, is used instead if a dynamic "OnChange" function. 

 

I spent a little time to write this script because display box GraphBuilderBox documentation is missing  in JSL Companion, 2nd Ed. ; this script will be used as an example for an addendum for the book. So I do know that sometimes it is difficult to recognize all the tools that might be available. The script and a sample data table is used. The script only depends upon the fact that the first column of the data table will always be X. Note from the display, check Inverse to use the Data Filter as a "do not use" option.

 

The script was tested on JMP  PRO 12, 13 and 14 on Windows OS.  It always amazes me how 52 lines of JSL that include comments and empty lines can do so much.

 

image.png

View solution in original post

6 REPLIES 6
ian_jmp
Staff

Re: JSL Stacked Bar graph for n number of columns

If you are looking for working code then, since every case can be a little different. some sample data would help folks get you on the right track.

 

To understand the general approach, I think you need to break down the task into two steps, namely getting the columns and then using Graph Builder. For the first, you probably need a 'ColListBox()' (the data filter works on rows not columns). Look for this in 'Help > Scripting Index'. For the second step, and because Graph Builder is very functional with lots of options, the requisite JSL can need a little care. 

0 Kudos
mt7575
New Contributor

Re: JSL Stacked Bar graph for n number of columns

Hi ian_jmp,

 

Thanks for the reply. I am attaching sample data which the graph builder uses to plot the stacked bar graph. 

 Table.jpg

Table.jpg is a screenshot showing sample data

 JMP:

   1. I have applied data filter to select the rows where the column name contains Fail and has non zero value

   2. I have plotted the selected rows using a graph builder where the X value is BIB_ID and Y values are all the fail columns

 

 JSL:

   I would like to parametrize the above-mentioned steps 

       1. There will be only BIB_ID column every time

       2. next column names or no. of columns change every time

 

Goal:

   1. Have to write JSL for kind of data mentioned in the Table.jpg to obtain a stacked bar graph as attached in the previous post. 

0 Kudos
gzmorgan0
Super User

Re: JSL Stacked Bar graph for n number of columns

@mt7575, when writing a script there are many questions that need to be answered; for example, is this expected to be an interactive display or create a graph and save it as a png? to a journal? to PPTX? You did not mention which verison of JMP you are using, which OS you have (there are some differences in MAC and Windows syntax), nor the level of your JSL skills. When teaching or writing about JSL or any scripting language, the best way to be effective is to "know your tools" which is another way of saying you need to have some basic skiils to write or even maintain a script someone else writes for you. 

Attached is a script written for an interactive display to select which items in X, and which Y's to plot.  It uses the following JSL "tools". For each item listed that you have not scripted, you should spend time in Help > Scripting Index,  exploring the scripts, options and messages. 

  •  Display boxes: FilterColSelector, ButtonBox, HListBox, VListBox, PanelBox, GraphBuilderBox
  • Objects: GraphBuilder, DataFilter, Expressions, Data Table

Not knowing your JSL skill, a Go button with an attached expression, is used instead if a dynamic "OnChange" function. 

 

I spent a little time to write this script because display box GraphBuilderBox documentation is missing  in JSL Companion, 2nd Ed. ; this script will be used as an example for an addendum for the book. So I do know that sometimes it is difficult to recognize all the tools that might be available. The script and a sample data table is used. The script only depends upon the fact that the first column of the data table will always be X. Note from the display, check Inverse to use the Data Filter as a "do not use" option.

 

The script was tested on JMP  PRO 12, 13 and 14 on Windows OS.  It always amazes me how 52 lines of JSL that include comments and empty lines can do so much.

 

image.png

View solution in original post

ian_jmp
Staff

Re: JSL Stacked Bar graph for n number of columns

"It always amazes me how 52 lines of JSL that include comments and empty lines can do so much." - Absolutely!

0 Kudos
Highlighted
mt7575
New Contributor

Re: JSL Stacked Bar graph for n number of columns

Hi gzmorgan,

 

Thank you for providing the solution. 

 

I am able to save the graph to ppt by adding the following line.

 

Thanks,

0 Kudos
mt7575
New Contributor

Re: JSL Stacked Bar graph for n number of columns

Above line only adds the first variable graph to the ppt.

Adding the following saves the entire graph to the ppt.
vdb << append( _vlb );
vdb << save presentation( "C:\Users\MT7575\Documents\analysis1.pptx", Append); //added line
0 Kudos