Have you compared how the script would look if Graph Builder built it? There is a small mistake in your code
Graph Builder(
Variables(
X(:SITE),
Y(:NPN1),
Y(:PNP1, Position(1)),
Y(:PNP2, Position(1)),
Y(:NPN2, Position(1))
),
Elements(Line(X, Y(1), Y(2), Y(3), Y(4), Legend(4)))
);
Notice how Position is used (you have extra []. You also had missing "," which I fixed when I added JSL formatting to your code so I could use JSL reformat easier).
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
gb = dt<< Graph Builder(
Show Control Panel(1),
Variables(X(:Site)),
Elements(Line(X,Y))
);
columns_list = {"NPN1", "PNP1", "PNP2", "NPN2"};
For Each({y_col, idx}, columns_list,
Eval(evalExpr(
gb << Add Variable({Expr(Name Expr(As Column(dt, y_col))), Position(1), Role("Y")})
));
);
-Jarmo