cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
Jay
Jay
Level I

How to loop generate graph for all columns

 Hi, Everyone

 

I trying to get my first loop work, but stuck with one issue.

 

It simply gets all cloumns, and loop through and plot all columns.  The problem is in

   test ==  ( y_cols[i] ) ;

My intension is test is the individual columns name,  but when i debug, it seems test is a list of all columns, same as the y_cols.

 

So when i run the script, it plots only the first column, many times.

 

 

 dt = Current Data Table();

 y_cols = dt << get column names(string);

 

Remove From(y_cols,1,2);

nw2 = new window("My first report");

 

for(i=1, i <=nitems(y_cols), i++,

 

   test ==  ( y_cols[i] ) ;

    

       gb=expr(Graph Builder(

             Size( 700,250 ),

             Show Control Panel( 0 ),

             Variables(

                    X( :Part id ),

                  Y( eval(test) ),

                    Overlay( :Time )

             ),

             Elements(

                    Points( X, Y, Legend( 12 ) ),

                    Line( X, Y, Legend( 14 ), Summary Statistic( "Median" ) )

             ),

             SendToReport(

                    Dispatch(

                          { },

                          "400",

                          ScaleBox,

                          {Legend Model(

                                 12,

                                 Base( 0, 14, 0 ),

                                 Base( 1, 14, 1 ),

                                 Base( 2, 14, 2 )

                          )}

                    )

             )

       )

       );

       nw2 << append(gb);

 );

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to loop generate graph for all columns

Here is a minor rework of your code to get the script to work.  The first part of the script just creqates a simple example data table.

Names Default to Here( 1 );
dt = New Table( "Test of Bivariate",
	Add Rows( 30 ),
	New Column(
		["en" => "NPN1", "ja" => "NPN1", "x-id" => "S_NPN1_Col", "zh-CN" => "NPN1"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[114.555760105678, 120.043693059459, 114.926510466106, 111.756445551183,
			111.545085144313, 113.52359591958, 111.749308571209, 114.411433304976,
			118.48975048042, 113.171122695149, 114.946183872216, 113.382890501824,
			114.666518192776, 107.884015560041, 113.065582322339, 116.25374611217,
			118.333680853156, 110.657545008855, 118.693111738676, 115.463396293845,
			110.287898508744, 113.287278281031, 115.219123741957, 112.385219593504,
			120.861530393886, 119.847995090729, 118.65519608864, 112.661846058518,
			114.066130117341, 114.063409994947]
		)
	),
	New Column(
		["en" => "PNP1", "ja" => "PNP1", "x-id" => "S_PNP1_Col", "zh-CN" => "PNP1"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[322.616751775796, 333.128079728678, 348.978757216574, 268.548094462492,
			295.073165929223, 323.833298568833, 369.320490694357, 342.987400315929,
			315.52243608245, 288.978183718528, 301.607366273833, 283.191076438161,
			212.800492311906, 341.443055295059, 331.555064642669, 278.646245766939,
			354.677433317207, 275.259301200618, 269.055788537937, 244.936754173054,
			469.298298488357, 380.107493803667, 307.351300272484, 395.390913757803,
			248.385309740161, 332.715779503856, 229.971512201935, 282.355854909556,
			278.876672135109, 369.802517417371]
		)
	),
	New Column(
		["en" => "PNP2", "ja" => "PNP2", "x-id" => "S_PNP2_Col", "zh-CN" => "PNP2"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[469.390289765043, 437.781112798903, 532.12814730405, 373.058628529111,
			338.900737368942, 469.992171436316, 563.084459366587, 479.378108668814,
			530.265608347575, 421.454501563007, 437.625180215708, 391.16014485917,
			336.315923666781, 459.675297352564, 556.117457880758, 393.524854048041,
			524.412197327866, 435.589457872556, 401.432160774864, 414.478191120167,
			549.457336783227, 481.694954348379, 415.372316833295, 590.034261426748,
			455.115879097893, 449.972226523986, 380.251466107595, 377.489216424948,
			429.808729569278, 482.221726694182]
		)
	),
	New Column(
		["en" => "NPN2", "ja" => "NPN2", "x-id" => "S_NPN2_Col", "zh-CN" => "NPN2"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[115.958473043434, 120.974137316372, 117.75312418797, 114.092607737274,
			113.778098130642, 116.488049497674, 115.935283026742, 115.762801088796,
			116.347793739608, 116.232907922575, 115.336672965867, 117.255145685653,
			118.901572658105, 110.399346473016, 117.429077171413, 117.119143668499,
			114.817571362932, 113.846330724714, 117.688752124707, 117.538298327714,
			112.904566955574, 116.425994464592, 115.927646041683, 114.612962021825,
			116.192793106131, 119.61138824619, 115.311215206548, 115.865219100186,
			115.64507142399, 114.59887334177]
		)
	),
	New Column(
		["en" => "PNP3", "ja" => "PNP3", "x-id" => "S_PNP3_Col", "zh-CN" => "PNP3"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[130.378809500886, 132.736937590235, 136.831952164704, 136.969154239163,
			136.622623419893, 137.480356512481, 138.094011176166, 142.10586919757,
			134.750041237898, 129.719685093372, 136.520172900026, 134.778624216716,
			136.991131754497, 140.420940666186, 143.257827228986, 132.213765487819,
			144.671172276421, 134.703176752174, 136.744212473486, 137.187637284245,
			139.788226018039, 139.372617199359, 136.112484488985, 142.809097034809,
			137.799370430979, 138.482493403385, 135.236982575217, 136.251777781494,
			130.768356509183, 138.248554728086]
		)
	),
	New Column(
		["en" => "IVP1", "ja" => "IVP1", "x-id" => "S_IVP1_Col", "zh-CN" => "IVP1"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[73.4842940932646, 75.6074915248983, 73.3304733114595, 75.7647427124531,
			70.5460961797334, 72.9451281758323, 75.6756511920958, 76.4874855218512,
			66.4572544989587, 72.2503891181424, 68.1130267608097, 78.8045562686784,
			76.4765647747647, 74.689323480678, 76.1706490573276, 75.7935715354233,
			72.2088629673599, 65.6494060910306, 75.7923931517876, 77.9990166080606,
			76.6172682677768, 73.7633567469775, 78.5651088817796, 69.8240361090062,
			72.0636364201829, 70.7582455389162, 69.7835283880779, 72.4529462963473,
			69.7646762627277, 75.321634759487]
		)
	),
	New Column( "Date",
		Numeric,
		"Ordinal",
		Format( "ddMonyyyy", 12 ),
		Input Format( "ddMonyyyy" ),
		Set Selected,
		Set Values(
			[3567542400, 3567628800, 3567715200, 3566678400, 3567542400, 3567888000,
			3566764800, 3568665600, 3568665600, 3566937600, 3566678400, 3566419200,
			3566332800, 3568060800, 3566246400, 3567715200, 3567196800, 3566505600,
			3566764800, 3568233600, 3566851200, 3566505600, 3566764800, 3568665600,
			3567456000, 3566246400, 3567801600, 3568492800, 3566419200, 3566160000]
		)
	),
	New Column( "Part ID",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
			1, 2, 3, 4, 1, 2]
		)
	)
);

y_cols = dt << get column names( string );
y_cols = Remove( y_cols, 7, 2 );
nw2 = New Window( "My first report" );

For( i = 1, i <= N Items( y_cols ), i++,
	test = y_cols[i];
	gb = //Expr(
	Graph Builder(
		Size( 700, 250 ),
		Show Control Panel( 0 ),
		Variables( X( :Part id ), Y( as column( test ) ), Overlay( :Date ) ),
		Elements( Points( X, Y, Legend( 12 ) ), Line( X, Y, Legend( 14 ), Summary Statistic( "Median" ) ) ),
		SendToReport(
			Dispatch(
				{},
				"400",
				ScaleBox,
				{Legend Model( 12, Base( 0, 14, 0 ), Base( 1, 14, 1 ), Base( 2, 14, 2 ) )}
			)
		)
		//)
	);
	nw2 << append( report(gb) );
	gb << close window;
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: How to loop generate graph for all columns

Here is a minor rework of your code to get the script to work.  The first part of the script just creqates a simple example data table.

Names Default to Here( 1 );
dt = New Table( "Test of Bivariate",
	Add Rows( 30 ),
	New Column(
		["en" => "NPN1", "ja" => "NPN1", "x-id" => "S_NPN1_Col", "zh-CN" => "NPN1"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[114.555760105678, 120.043693059459, 114.926510466106, 111.756445551183,
			111.545085144313, 113.52359591958, 111.749308571209, 114.411433304976,
			118.48975048042, 113.171122695149, 114.946183872216, 113.382890501824,
			114.666518192776, 107.884015560041, 113.065582322339, 116.25374611217,
			118.333680853156, 110.657545008855, 118.693111738676, 115.463396293845,
			110.287898508744, 113.287278281031, 115.219123741957, 112.385219593504,
			120.861530393886, 119.847995090729, 118.65519608864, 112.661846058518,
			114.066130117341, 114.063409994947]
		)
	),
	New Column(
		["en" => "PNP1", "ja" => "PNP1", "x-id" => "S_PNP1_Col", "zh-CN" => "PNP1"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[322.616751775796, 333.128079728678, 348.978757216574, 268.548094462492,
			295.073165929223, 323.833298568833, 369.320490694357, 342.987400315929,
			315.52243608245, 288.978183718528, 301.607366273833, 283.191076438161,
			212.800492311906, 341.443055295059, 331.555064642669, 278.646245766939,
			354.677433317207, 275.259301200618, 269.055788537937, 244.936754173054,
			469.298298488357, 380.107493803667, 307.351300272484, 395.390913757803,
			248.385309740161, 332.715779503856, 229.971512201935, 282.355854909556,
			278.876672135109, 369.802517417371]
		)
	),
	New Column(
		["en" => "PNP2", "ja" => "PNP2", "x-id" => "S_PNP2_Col", "zh-CN" => "PNP2"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[469.390289765043, 437.781112798903, 532.12814730405, 373.058628529111,
			338.900737368942, 469.992171436316, 563.084459366587, 479.378108668814,
			530.265608347575, 421.454501563007, 437.625180215708, 391.16014485917,
			336.315923666781, 459.675297352564, 556.117457880758, 393.524854048041,
			524.412197327866, 435.589457872556, 401.432160774864, 414.478191120167,
			549.457336783227, 481.694954348379, 415.372316833295, 590.034261426748,
			455.115879097893, 449.972226523986, 380.251466107595, 377.489216424948,
			429.808729569278, 482.221726694182]
		)
	),
	New Column(
		["en" => "NPN2", "ja" => "NPN2", "x-id" => "S_NPN2_Col", "zh-CN" => "NPN2"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[115.958473043434, 120.974137316372, 117.75312418797, 114.092607737274,
			113.778098130642, 116.488049497674, 115.935283026742, 115.762801088796,
			116.347793739608, 116.232907922575, 115.336672965867, 117.255145685653,
			118.901572658105, 110.399346473016, 117.429077171413, 117.119143668499,
			114.817571362932, 113.846330724714, 117.688752124707, 117.538298327714,
			112.904566955574, 116.425994464592, 115.927646041683, 114.612962021825,
			116.192793106131, 119.61138824619, 115.311215206548, 115.865219100186,
			115.64507142399, 114.59887334177]
		)
	),
	New Column(
		["en" => "PNP3", "ja" => "PNP3", "x-id" => "S_PNP3_Col", "zh-CN" => "PNP3"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[130.378809500886, 132.736937590235, 136.831952164704, 136.969154239163,
			136.622623419893, 137.480356512481, 138.094011176166, 142.10586919757,
			134.750041237898, 129.719685093372, 136.520172900026, 134.778624216716,
			136.991131754497, 140.420940666186, 143.257827228986, 132.213765487819,
			144.671172276421, 134.703176752174, 136.744212473486, 137.187637284245,
			139.788226018039, 139.372617199359, 136.112484488985, 142.809097034809,
			137.799370430979, 138.482493403385, 135.236982575217, 136.251777781494,
			130.768356509183, 138.248554728086]
		)
	),
	New Column(
		["en" => "IVP1", "ja" => "IVP1", "x-id" => "S_IVP1_Col", "zh-CN" => "IVP1"],
		Numeric,
		"Continuous",
		Format( "Best", 10 ),
		Set Property(
			"Spec Limits",
			{LSL( 104.412948990151 ), USL( 131.893493064355 ),
			Target( 118.153221027253 ), Show Limits( 1 )}
		),
		Set Values(
			[73.4842940932646, 75.6074915248983, 73.3304733114595, 75.7647427124531,
			70.5460961797334, 72.9451281758323, 75.6756511920958, 76.4874855218512,
			66.4572544989587, 72.2503891181424, 68.1130267608097, 78.8045562686784,
			76.4765647747647, 74.689323480678, 76.1706490573276, 75.7935715354233,
			72.2088629673599, 65.6494060910306, 75.7923931517876, 77.9990166080606,
			76.6172682677768, 73.7633567469775, 78.5651088817796, 69.8240361090062,
			72.0636364201829, 70.7582455389162, 69.7835283880779, 72.4529462963473,
			69.7646762627277, 75.321634759487]
		)
	),
	New Column( "Date",
		Numeric,
		"Ordinal",
		Format( "ddMonyyyy", 12 ),
		Input Format( "ddMonyyyy" ),
		Set Selected,
		Set Values(
			[3567542400, 3567628800, 3567715200, 3566678400, 3567542400, 3567888000,
			3566764800, 3568665600, 3568665600, 3566937600, 3566678400, 3566419200,
			3566332800, 3568060800, 3566246400, 3567715200, 3567196800, 3566505600,
			3566764800, 3568233600, 3566851200, 3566505600, 3566764800, 3568665600,
			3567456000, 3566246400, 3567801600, 3568492800, 3566419200, 3566160000]
		)
	),
	New Column( "Part ID",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values(
			[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
			1, 2, 3, 4, 1, 2]
		)
	)
);

y_cols = dt << get column names( string );
y_cols = Remove( y_cols, 7, 2 );
nw2 = New Window( "My first report" );

For( i = 1, i <= N Items( y_cols ), i++,
	test = y_cols[i];
	gb = //Expr(
	Graph Builder(
		Size( 700, 250 ),
		Show Control Panel( 0 ),
		Variables( X( :Part id ), Y( as column( test ) ), Overlay( :Date ) ),
		Elements( Points( X, Y, Legend( 12 ) ), Line( X, Y, Legend( 14 ), Summary Statistic( "Median" ) ) ),
		SendToReport(
			Dispatch(
				{},
				"400",
				ScaleBox,
				{Legend Model( 12, Base( 0, 14, 0 ), Base( 1, 14, 1 ), Base( 2, 14, 2 ) )}
			)
		)
		//)
	);
	nw2 << append( report(gb) );
	gb << close window;
);
Jim
Jay
Jay
Level I

Re: How to loop generate graph for all columns

Thank you. Jim.  That worked.