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
ToddKeebler
Level I

How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Hi,

 

I'm writing a script that will work with files that have a variety of columns, so I had to modify an example I found on here which concatenates the Graph Builder call based on the number of columns.  Despite being clumsy, it does seem to work, but my issue is that I then want to change the X-axis to log scale, change the limits, etc.  I tried a few approaches from the Scripting Index and examples, but none seemed to work.

 

Would very much appreciate a pointer in the right direction on the axis settings, but if anybody has an idea of how to do initial graphing portion better, that would be great too, thanks!

 

 

dt = Current Data Table();
ColNameList = dt << Get Column Names (continuous, string);

//Start with initial graph builder
GraphExpr = "
TestGraph = Graph Builder(
	Size( 534, 456 ),
	Show Control Panel( 0 ),
	
	Variables(";
		
//Add X Entry
GraphExpr = GraphExpr || "
		X( :Name( \!"" || ColNameList[1] || "\!") ),";

//Add the first Y entry
GraphExpr = GraphExpr || "
		Y( :Name( \!"" || ColNameList[2] || "\!") ),";

//Add the second Y entry
For( i = 3, i <= N items (ColNameList), i++,
GraphExpr = GraphExpr || "
		Y( :Name( \!"" || ColNameList[i] || "\!"), Position (1) ),";
);


//Close out Variables section
GraphExpr = GraphExpr || "
	),
	Elements( 
		Line( X, Y( 1 )";

//Build out the lines for all columns
For( i = 2, i <= N items (ColNameList), i++,
	GraphExpr = GraphExpr || ", Y( " || char(i) || " )"
);

GraphExpr = GraphExpr || ", Legend( 1 ) 
		) 
	) 
)";

eval(parse(GraphExpr));

TestGraph << Show Legend (0);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

All of the messages that change an axis are available in the scripting index entry for AxisBox

What you want to use, is

 

report(TestGraph)[AxisBox(2)] << scale(log);

 

Jim

View solution in original post

7 REPLIES 7
Thierry_S
Super User

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Hi,

This is indeed rather convoluted way to build a Graph Builder expression. You might want to look into the approach of defining your entire GB expression with "placeholders" (gbe = Expr (Graph Builder(...)); use the substitute function to replace your placeholders with column, variables, labels, etc.., and then use the Eval() function to generate the graph (sorry I don't have the time right now to provide more details)

 

For your specific question, if you assign your Graph Builder expression to a variable (e.g., gb = Graph Builder (...);) you can then use the approach below to update the axis in any way you need:

gb = dt << Graph Builder(
	Show Control Panel( 0 ),
	Variables(
		X( :age, Size( 23 ) ),
		Y( :height, Size( 37 ) ),
		Y( :weight, Position( 1 ), Size( 37 ), Side( "Right" ) )
	),
	Elements( Points( X, Y( 1 ), Legend( 1 ), Jitter( 1 ) ), Points( X, Y( 2 ), Legend( 3 ), Jitter( 1 ) ) )
);
framebox = Report( gb )[framebox( 1 )];
framebox << Y Axis(
	Scale ("Log"),
	Add Ref Line( 61.25, "Solid", "Medium Dark Green" ),
	Show Major Grid( 1 ),
	Show Minor Grid( 1 ),
	Format( "Fixed Dec", 5, 2 ),
	Rotated Labels( "Perpendicular" )
);

I hope this helps.

Best,

TS

Thierry R. Sornasse
txnelson
Super User

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

All of the messages that change an axis are available in the scripting index entry for AxisBox

What you want to use, is

 

report(TestGraph)[AxisBox(2)] << scale(log);

 

Jim
ToddKeebler
Level I

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Hey Jim, thanks for the quick response on that.  That works well.  I didn't realize you needed to use report() to reference that graph item, I was just trying to use TestGraph[AxisBox(2)] << scale(log)

 

Thanks,

 

Todd

hogi
Level XII

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Is there a description how this can be done for Gradient Legend settings?

I tried

Report( gb)[Legend Box(1)] << Legend Model( ...

 

but it didn't work

jmpfumbler
Level I

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Hi everyone,

I have kind of similar question, on how to automate the X axis, which is time scale & I would like it to be automatically displayed the data from the last desired period.(n=7) for example.

Much appreciated for your helps.

Linh

My script as below:

jmpfumbler_0-1708620751309.png

 

pmroz
Super User

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Hi @jmpfumbler can you post the code using the <JSL> button rather than a picture?

Thanks!

jmpfumbler
Level I

Re: How Do I Change Scale of X-Axis after using Graph Builder in JSL (and graphing approach question)

Hi Pmroz,
Script with JSL,
Thank you,
// → Data Table( "GSB" ) Local( {obj}, obj = Data Table( "GSB" ) << Graph Builder( Size( 604, 659 ), Variables( X( Transform Column( "Month Year[Date Measured]", Ordinal, Format( "m/y", 23 ), Formula( Date DMY( 1, Month( :Date Measured ), Year( :Date Measured ) ) ) ) ), Overlay( GSB Validation ) ), Elements( Bar( X, Legend( 11 ), Bar Style( "Stacked" ), Summary Statistic( "% of Factor" ), Label( "Label by Value" ) ) ), Local Data Filter( Add Filter( columns( :"Inferred Value (Yes/No)"n, Transform Column( "Month Year[Date Measured]", Ordinal, Format( "m/y", 23 ), Formula( Date DMY( 1, Month( :Date Measured ), Year( :Date Measured ) ) ) ) ), Where( :"Inferred Value (Yes/No)"n == "Yes" ), Where( Transform Column( "Month Year[Date Measured]", Ordinal, Format( "m/y", 23 ), Formula( Date DMY( 1, Month( :Date Measured ), Year( :Date Measured ) ) ) ) == {3755376000, 3758054400, 3760473600, 3763152000, 3765744000, 3768422400, 3771014400, 3773692800, 3776371200, 3778963200, 3781641600} ), Display( Transform Column( "Month Year[Date Measured]", Ordinal, Format( "m/y", 23 ), Formula( Date DMY( 1, Month( :Date Measured ), Year( :Date Measured ) ) ) ), N Items( 15 ) ) ) ), SendToReport( Dispatch( {}, "graph title", TextEditBox, {Set Text( "Monthly GSB Validation (%)" )} ), Dispatch( {}, "Y title", TextEditBox, {Set Text( "%" )} ), Dispatch( {}, "Where((Inferred Value (Yes", TextBox, {Hide( 1 )} ) ) ); obj << Save Script to Data Table( "Monthly GSB Validation (%)", <<Replace( 1 ), <<Prompt( 0 ) ); obj << Close Window; ); Graph Builder( Transform Column( "Year Week[Date Measured]", Character, Formula( Local( {w = Week Of Year( :Date Measured, 3 ), y = Year( :Date Measured ), m = Month( :Date Measured )}, If( Is Missing( :Date Measured ), "", Char( If( m / w >= 12, y + 1, w / m >= 52, y - 1, y ) ) || If( w >= 10, "W", "W0" ) || Char( w ) ) ) ) ), Size( 570, 619 ), Variables( X( :"Year Week[Date Measured]"n ), Overlay( :Best product ) ), Elements( Bar( X, Legend( 2 ), Bar Style( "Stacked" ), Summary Statistic( "% of Factor" ), Label( "Label by Value" ) ) ), Local Data Filter( Add Filter( columns( :"Year Week[Date Measured]"n ), Where( :"Year Week[Date Measured]"n == {"2023W48", "2023W49", "2023W50", "2023W51", "2023W52", "2024W01", "2024W02", "2024W03", "2024W04", "2024W05", "2024W06", "2024W07", "2024W08"} ), Display( :"Year Week[Date Measured]"n, N Items( 15 ), Find( Set Text( "" ) ) ) ) ), SendToReport( Dispatch( {}, "Where(Year Week[Date Measured] = 2023W48, 2023W49, 2023W50, 2023W51, 2023W52, 2024W01, 2024W02, 2024W03, 2024W04, 2024W05, 2024W06, 2024W07, 2024W08)", TextBox, {Hide( 1 )} ) ) );