First off, if you are going to pursue JSL coding, you need to thourthly read the Scripting Guide
Help==>Books==>Scripting Guide
Below is a reworking of your script to illustrate how to loop using a function and how to keep all of the output in the same output journal. I know it is not exactly what you need, but it should give you a good start on how to do what you want
Names Default To Here( 1 );
dt = Current Data Table();
doGraphPlot = Function(
{dt, Xaxis, Yaxis, Grby, chnl},
Eval(
Substitute(
Expr(
gb = dt << Graph Builder(
invisible,
where( dt:Channel == __chnl__ ),
size( 600, 400 ),
show control panel( 0 ),
variables(
Y( Eval( Yaxis ) ),
X( Eval( Xaxis ) ),
Group X( Eval( Xgrby ) ),
Overlay( :RowCol )
),
elements( smoother( X, Y, legend( 19 ), lambda( 0.0001 ) ) )
)
),
Expr( __chnl__ ), chnl
)
);
Report( gb )[Outline Box( 1 )] << set title( "Channel = " || Char( chnl ) );
);
jjrn = New Window( "Data Plot - Output_1 vs Input", <<Journal );
dtsum = dt << Summary( Group( :Channel ), invisible ); //
Yaxis = Expr(
Column( dt, "Output_1" )
);
Xaxis = Expr( Column( dt, "Input" ) );
Xgrby = Expr(
Column( dt, "wafer_number" )
);
For( i = 1, i <= N Row( dtsum ), i++,
chnl = dtsum:Channel[i];
doGraphPlot( dt, Yaxis, Xaxis, Xgrby, chnl );
jjrn << append( Report( gb ) );
gb << close window;
);
Yaxis = Expr(
Column( dt, "Output_3" )
);
Xaxis = Expr( Column( dt, "Input" ) );
Xgrby = Expr(
Column( dt, "wafer_number" )
);
For( i = 1, i <= N Row( dtsum ), i++,
chnl = dtsum:Channel[i];
doGraphPlot( dt, Yaxis, Xaxis, Xgrby, chnl );
jjrn << append( Report( gb ) );
gb << close window;
);
Close( dtsum, nosave );
Jim