I think you just need to save a reference to the new table when you open it and then send the graph builder script to that reference. Just running Graph Builder() will run it against the current data table, which might not be the one you want. For example note the role of dt2 in this script:
Names default to here(1);
dt1 = Open("$Sample_data/big class.jmp");
dt2 = New SQL Query(
Version( 130 ),
Connection( "JMP" ),
JMP Tables(
Associative Array({{dt1 << Get Name, "_MEMORY_"}})
),
QueryName( "SQLQuery1" ),
Select(
Column(
"height",
"t1",
Alias( "Average-height" ),
SavedJMPName( "height" ),
Aggregation( "Average" )
),
Column(
"age",
"t1",
Analysis Type( "Ordinal" ),
Numeric Format( "Fixed Dec", "0", "NO", "" )
)
),
From( Table( "big class", Alias( "t1" ) ) ),
Group By(
Column(
"age",
"t1",
Analysis Type( "Ordinal" ),
Numeric Format( "Fixed Dec", "0", "NO", "" )
)
)
) << Run;
dt2 << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :age ), Y( :"Average-height"n ) ),
Elements( Points( X, Y, Legend( 3 ) ) )
);