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

Setting graph axes and titles as variables

Hello all, newbie here:

 

im working with a set of data in a process that i am expecting to repeat many many times, as such i'm trying to automate the set up as best i can. For the moment i'm working on some data presentation, ansd i need your help in making a graph's axis titles variable depending on the content of cells.

as an example i have the data below :

 

MachineCapybara_3-1669388412498.png

 

 

 

from this data i want to plot a graph showing "Res" for each "Col A" value, as well as a series of reference lines showing "Ref" (and its boundary conditions "+/-uref" and "rob" and its boundary conditions "+/- urob".

Currently the  script is as follows:

dt = Current Data Table();

Graph Builder(
	Size( 743, 472 ),
	Show Control Panel( 0 ),
	Variables(
		X( :COLA, Order By( :Res, Ascending, Order Statistic( "Mean" ) ) ),
		Y( :Res ),
		Interval( :Ures )
	),
	Elements( Points( X, Y, Legend( 7 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"COLA",
			ScaleBox,
			{Label Row(
				{Label Orientation( "Vertical" ), Set Font Size( 12 ),
				Set Font Style( "Italique" )}
			)}
		),
		Dispatch(
			{},
			"Res",
			ScaleBox,
			{Min(), Max(), Inc(), Minor Ticks( 1 ),
			Add Ref Line( dt[1, 11], "Solid", "Dark Blue", "", 1 ),
			Add Ref Line( dt[1, 9], "Dotted", "Dark Blue", "", 1 ),
			Add Ref Line( dt[1, 10], "Dotted", "Dark Blue", "", 1 ),
			Add Ref Line( dt[1, 4], "Solid", "Dark Red", "", 1 ),
			Add Ref Line( {dt[1, 7], dt[1, 8]}, "Solid", "Medium Dark Red", "", 1, 0.15 ),
			Add Ref Line( dt[1, 7], "Dotted", "Dark Red", "", 1 ),
			Add Ref Line( dt[1, 8], "Dotted", "Dark Red", "", 1 )}
		),
		Dispatch( {}, "graph title", TextEditBox, {Set Text( "Analyte res" )} ),
		Dispatch( {}, "X title", TextEditBox, {Set Text( "COLA" )} ),
		Dispatch( {}, "Y title", TextEditBox, {Set Text( "Units of Res (g/m3)" )} ),
		Dispatch( {}, "400", LegendBox, {Legend Position( {7, [-1, -3]} )} )
	)
);

 

Which works fine and is flexible enough to be able to modify the reference lines in the graph according to the cell values as required.

 

Now, what i'd like is also for the titles to be able to do the same thing as the reference lines. So ideally i could add an initial column in my jmp table, which we will call "info" which has the information on the studied analyte (name, units used for measurement, etc...) and i'd like for the graph's title (and axes) to pull the information out from these cells (like the reference lines are currently doing) and use this info in the text.

 

For example, if in my "info" column i have "Zr4+" i'd like the final graph to go and look for this cell and use it to label itself or one of its axes.Such that i can then change the cell to "Br7-" and the next time i run the script, the new graph will be labelled with "Br7-".

 

Is it possible to do this?

 

bonus points if the variable can be inserted in a longer text, eg the y axis is "Zr 4+ (mg/l)" and then changes to "Br7- (mg/l)"  

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Setting graph axes and titles as variables

I added a new Info column to your data table

txnelson_0-1669393965163.png

And modified your script to use it to get the values for the labels.  I also modified your script to used a more direct way to add the reference lines to the chart.

txnelson_1-1669394156998.png

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

gb = dt << Graph Builder(
	Size( 743, 472 ),
	Show Control Panel( 0 ),
	Variables( X( :COLA, Order By( :Res, Ascending, Order Statistic( "Mean" ) ) ), Y( :Res ), Interval( :Ures ) ),
	Elements( Points( X, Y, Legend( 7 ) ) ),
	SendToReport(
		Dispatch( {}, "COLA", ScaleBox, {Label Row( {Label Orientation( "Vertical" ), Set Font Size( 12 ), Set Font Style( "Italique" )} )} ),
		Dispatch( {}, "Res", ScaleBox, {Min(), Max(), Inc(), Minor Ticks( 1 )} ), 
		Dispatch( {}, "400", LegendBox, {Legend Position( {7, [-1, -3]} )} )
	)
);

gbr = gb << report;
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 11], "Solid", "Dark Blue", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 9], "Dotted", "Dark Blue", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 10], "Dotted", "Dark Blue", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 4], "Solid", "Dark Red", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( {dt[1, 7], dt[1, 8]}, "Solid", "Medium Dark Red", "", 1, 0.15 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 7], "Dotted", "Dark Red", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 8], "Dotted", "Dark Red", "", 1 );

gbr[TextEditBox(1)] << set text(column(dt,"info")[1]);
gbr[TextEditBox(3)] << set text(column(dt,"info")[2]);
gbr[TextEditBox(4)] << set text(column(dt,"info")[3]);

 

 

Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Setting graph axes and titles as variables

I added a new Info column to your data table

txnelson_0-1669393965163.png

And modified your script to use it to get the values for the labels.  I also modified your script to used a more direct way to add the reference lines to the chart.

txnelson_1-1669394156998.png

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

gb = dt << Graph Builder(
	Size( 743, 472 ),
	Show Control Panel( 0 ),
	Variables( X( :COLA, Order By( :Res, Ascending, Order Statistic( "Mean" ) ) ), Y( :Res ), Interval( :Ures ) ),
	Elements( Points( X, Y, Legend( 7 ) ) ),
	SendToReport(
		Dispatch( {}, "COLA", ScaleBox, {Label Row( {Label Orientation( "Vertical" ), Set Font Size( 12 ), Set Font Style( "Italique" )} )} ),
		Dispatch( {}, "Res", ScaleBox, {Min(), Max(), Inc(), Minor Ticks( 1 )} ), 
		Dispatch( {}, "400", LegendBox, {Legend Position( {7, [-1, -3]} )} )
	)
);

gbr = gb << report;
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 11], "Solid", "Dark Blue", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 9], "Dotted", "Dark Blue", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 10], "Dotted", "Dark Blue", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 4], "Solid", "Dark Red", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( {dt[1, 7], dt[1, 8]}, "Solid", "Medium Dark Red", "", 1, 0.15 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 7], "Dotted", "Dark Red", "", 1 );
gbr[AxisBox( 2 )] << Add Ref Line( dt[1, 8], "Dotted", "Dark Red", "", 1 );

gbr[TextEditBox(1)] << set text(column(dt,"info")[1]);
gbr[TextEditBox(3)] << set text(column(dt,"info")[2]);
gbr[TextEditBox(4)] << set text(column(dt,"info")[3]);

 

 

Jim

Re: Setting graph axes and titles as variables

)Dear Jim, thank you for that, that does the trick!

Re: Setting graph axes and titles as variables

Hello Jim,

I've been playing a bit more with the script and the axes titles.

The solution you provided works great for basic stuff, i was wondering if there's a way to introduce a variable element and a fixed element in the "set text" part.

 

Eventually, from the script you helped me work on i'm pulling three or four different graphs, now i'd like the title for each graph to pull text from one cell and incorporate it into another text (from another cell, or written directly into a script, i'm not fussy.

 

To explain myself, currently the title of my graph will end up as "analyte res" (which is already leagues ahead of where i was before) , i'd like to go one step further and have something like "graph 5 : [Analyte res]" such that i can just change the "analyte res" part and it will change the title. in a similar fashion it would be nice to be able to have the y axis labeled as "[analyte] [quantity measured (mass, concentration, volume, ...)] [unit (g, mg/L, cm3...)]" such that i can then change each of the three variables in chosen cells according to my needs for each different graph.

 

I've played around with the "set text" parameter but it doesn't seem to like a mixed system like that (or even pulling from multiple cells). so my most promising workaround is just to add a text box next to the title and y axis, although of course its not an elegant solutuon and i suspect that in certain cases i need to be careful not to induce overlap between the two text boxes....

 

Any ideas? 

txnelson
Super User

Re: Setting graph axes and titles as variables

The issue you appear to be having is how to provide to the TextEditBox() the properly syntaxed element. 

The specification for Set Text, as found in the Scripting Index is:

txnelson_0-1669724226234.png

So basically, what has to be provided is a "String".  In JSL, pretty much anything can be put into a string.  From the example in the sample script 

gbr[TextEditBox(1)] << set text(column(dt,"info")[1]);

The value from the first row of the "info" column is being sent to the TextEditBox(), and since the column "Indo" has a Modeling Type of Character, the values in each cell is a "String".

JSL allows the building of Strings in many different ways.  I strongly suggest that you take the time to read the Scripting Guide that can be found in the JMP Documentation Library, available under the Help pull down menu.

But for simple illustration, if you want to have "Graph 5 Analysis Res it could simply be stated as 

gbr[TextEditBox(1)] << set text( "Graph 5 " || column(dt,"info")[1]);

Where the string passed to the TextEdibox()  is a String made from concatenating the string "Graph 5 " with the string from the cell from the first row of the column Info.

Jim

Re: Setting graph axes and titles as variables

Thank you for this,

i will do as you say and read the guide. Indeed, my work with JSL is the first time i've actually done scripting/coding in my life so there's a lot of specific logics i still need to learn!