cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

using a variable as column name when creating a plot

 

The script below loads some data and should create twice the same plot.
The first one by referring to the column name by using a variable (test1),
the second one by calling the column name directly. 
The second one works fine, but for the first one I get an empty plot area. I guess there is a problem with how I define or call test1. I have tried different approaches, but so far nothing worked.

Names Default To Here( 1 );

// Import the Excel file with specified settings
dt = Open(
    "/Y:/.../file.xlsx",
    Worksheets( "Pivot table for JMP" ),
    Worksheet Settings(
        1,
        Has Column Headers( 1 ),
        Headers Start on Row( 2 ),
        Data Starts on Row( 3 )
    )
);

// Filter rows to include only "AAA" in "Common Designation"
dt_AAA = dt << Subset(
    Rows( :Common Designation == "AAA" ),
    Include All Columns,
    Name( "Filtered AAA" )
);

size = "AAA" ;

Match( size,
	"AAA", test1 =  column ("PL (min)"),
);

New Window( size,
	
	V List Box(
		Graph Builder(
			Size( 500, 297 ),
			Show Control Panel( 0 ),
			Variables( X( :test1 ), Y( :Chemistry ), Color( :Chemistry ) ),
			Elements( Points( X, Y, Legend( 106 ) ) )
		),
		Graph Builder(
			Size( 500, 297 ),
			Show Control Panel( 0 ),
			Variables( X( :"PL (min)"n ), Y( :Chemistry ), Color( :Chemistry ) ),
			Elements( Points( X, Y, Legend( 106 ) ) )
		),
	),
);

 

 

2 REPLIES 2

Re: using a variable as column name when creating a plot

If I'm understanding correctly, I think you just need to remove the colon in front of test1 in the first Graph Builder script. Here's an example script that works:

Names Default To Here (1);
dt = open ("$SAMPLE_DATA/big class.jmp");
test1 = column ("weight");

Graph Builder (
	Variables (X(test1), Y(:height), color (:sex))
);
hogi
Level XIII

Re: using a variable as column name when creating a plot

A cool trick to find bugs like this:
remove more and more lines from the buggy script. Till there are just enough lines to produce the error.
important: the code should contain all ingredients to produce the error - for everybody who executes the code *)

 

This has 2 advantages:
- in most of the cases, one finds the bug automatically. 1 line removed, the bug is gone.

- the remaining code is very short, this makes it much easier to find the bug.

 

*) on my system, it crashed with the error message:

hogi_0-1765563090008.png

much better: use one of the sample files, like in @Jed_Campbell 's example.
This has another benefit: you can differentiate between:
- there is an error in my data table (and the error is gone with the example data)
- there is an error in my script (because I can reproduce the error with the sample data)

Recommended Articles