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);
GraphicsScriptingRe: 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
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);