The following is an example of the basic structure of a Graph Builder script:
Graph Builder(
Size( x, y ),
// Use any commands from the red triangle menu - Size is an example
Variables( role( column ), ...), //Required
Elements( element name( element options, ...), //Required
Data Filter( ... ),
// Use any display customizations here - Data Filter is an example
);
The following is an example of a simple Graph Builder script that creates a bar chart:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Graph Builder(Variables(
X( :age ),
Y( :weight ) ),
Elements( Bar( X, Y, Legend( 8 ) ) )
// Legend is not required, but provides an internal legend ID that you can use for later customization
);
The following is a more detailed Graph Builder script that creates a bar chart:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Graph Builder(
Size( 373, 332 ),
Show Control Panel( 0 ),
Variables(
X( :age ),
Y( :weight ),
Y( Transform Column( "weight25",
Formula( Col Quantile( :weight, 0.25, :age ) )
),
Position( 1 )
/* By default each Y variable gets its own axis, but the Position(1)
option keeps each additional Y in the first slot and merges the axes. */
),
Y( Transform Column( "weight75", Formula( Col Quantile( :weight, 0.75, :age ) ) ),
Position( 1 )
)
),
Elements(
Bar( X, Y( 2 ), Y( 3 ), Legend( 10 ), Bar Style( "Range" ) ),
// This bar element uses only the second and third Y variables and
// draws a Range bar between the values.*/
Bar( X, Y( 1 ), Legend( 8 ),
Bar Style( "Float" ), Summary Statistic( "Median" )
// This bar element uses the first Y variable and draws its median with the
// float style, which is a short horizontal line
),
Points( X, Y( 1 ), Legend( 9 ) )
// The Points element shows the raw data as markers.
),
SendToReport(
// Contains display customizations
Dispatch( {}, "400", ScaleBox,
// 400 is the fixed name
{Legend Model( 10,
Level Name( 0, "1st to 3rd
quartiles",
Item ID( "Mean(weight25)..Mean(weight75)", 1 )
// Renames the legend, moves the legend name onto several lines, and changes
// the color for legend 10 (the Range bar)
),
Properties( 0, {Fill Color( 32 )},
Item ID( "Mean(weight25)..Mean(weight75)", 1 )
// Changes the color for legend 10 (the range bar)
)
), Legend Model( 9,
Properties( 0, {Marker Size( 4 )}, Item ID( "weight",1 ) )
// Changes the marker size for legend 9 (the Points element)
)}
),
Dispatch( {}, "graph title", TextEditBox,
{Set Text( "Weights with quartile ranges" )}
// Changes the graph title
),
Dispatch( {}, "Y title", TextEditBox, {Set Text( "weight" )} ),
// Changes the Y axis title
Dispatch( {}, "400", LegendBox,
// Hides the legend item for legend 9 by giving it a position of -1
{Legend Position( {10, [0], 8, [1], 9, [-1]} )}
)
)
);
Use the Type Properties option to apply default properties to new legend items based on their type, regardless of specific property overrides. Apply Type Properties to any legend types that are not explicitly set by a Property clause.
Note: A specific Property clause overrides a general Type Properties clause.
With Type Properties, the first argument is always 0, and the second argument specifies the legend type. When the legend changes (for example, if you add an overlay variable or change data filters and new legend items appear), the Type Properties clause ensures that these default properties are applied to any new items of that type. In the following example, the Marker Size is set to 6 and the Line width is set to 5.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :height ), Y( :weight ), Overlay( :sex ) ),
Elements( Points( X, Y, Legend( 2 ) ), Smoother( X, Y, Legend( 3 ) ) ),
SendToReport( Dispatch( {}, "400", ScaleBox,
{Legend Model( 2, Type Properties( 0, "Marker", {Marker Size( 6 ), Transparency( 0.4 )})),
Legend Model( 3, Type Properties( 0, "H Line", {Line Width( 5 )} ))}
))
);