Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
LeeP
Level III

How to Save Group By Charts Individually

I'm trying to automate my JMP chart creation. I've been using  the following as a guide: Automated Report Creation From Data Import to Publication 2019

I've gotten to the point where I can create all of the charts. Now I'm working on saving them and having a hard time determining how. I am generating a P Chart report that is grouped by some value in the underlying data table. The report comes out with multiple P Charts, one for each group by value. I want to save each one individually to a seperate HTML page. So for example, if I had a report that grouped on "Planets" and the report had charts for each planet, I want to have an HTML page with the chart for each Planet instread of a signle HTML page with all of the planets. Is this possible and if so, how. Attached is my sample script.

 

planetQ = New SQL Query(
	Connection(
		"CONNECTION INFO HERE"
	),
	QueryName( "ON_TIME_SPC_PLANET" ),
	Select(
		Column( "ReleaseMonth", "t1", Numeric Format( "m/d/y", "-1", "NO", "" ) ),
		Column( "PLANET", "t1" ),
		Column(
			"On-Time",
			"t1",
			Alias( "Sum-On-Time" ),
			SavedJMPName( "On-Time" ),
			Aggregation( "Sum" ),
			JMP Name( "Sum-On-Time", 0 )
		),
		Column(
			"Total",
			"t1",
			Alias( "Sum-Total" ),
			SavedJMPName( "Total" ),
			Aggregation( "Sum" ),
			JMP Name( "Sum-Total", 0 )
		),
		Column( "Phase", "t1", Analysis Type( "Nominal" ) )
	),
	From( Table( "ON_TIME_SPC", Schema( "dbo" ), Alias( "t1" ) ) ),
	Group By(
		Column( "ReleaseMonth", "t1", Numeric Format( "m/d/y", "-1", "NO", "" ) ),
		Column( "PLANET", "t1" ),
		Column( "Phase", "t1" )
	),
	Order By(
		Column(
			"ReleaseMonth",
			"t1",
			Numeric Format( "m/d/y", "-1", "NO", "" ),
			Order( "Ascending" )
		)
	)
) << Run Foreground();

planetQ << New Column( "OnTimePct",
	Formula( :Name( "Sum-On-Time" ) / :Name( "Sum-Total" ))
);
wait(1.0);

current data table(planetQ);

planetP = Control Chart(
	Sample Label( :ReleaseMonth ),
	Phase( :Phase ),
	Sample Size( :Name( "Sum-Total" ) ),
	KSigma( 3 ),
	Chart Col( :OnTimePct, P( Phase Level( "1" ), Phase Level( "2" ) ) ),
	By( :PLANET )
);
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ian_jmp
Staff

Re: How to Save Group By Charts Individually

Here's an example you should be able to adapt:

NamesDefaultToHere(1);

// Get some data
dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Run the platform. NB: ccb is a list, because of teh use of the 'By' variable
ccb = dt << Control Chart Builder(
						Show Control Panel( 0 ),
						Show Limit Summaries( 0 ),
						Show Capability( 0 ),
						Variables( Y( :height ) ),
						By( :sex)
					);

// Save the report for each level of the 'By' variable
for(c=1, c<=NItems(ccb), c++,
	// Get the current report layer
	thisrep = Report(ccb[c]);
	// Get the first outline box
	firstOB = thisrep[OutlineBox(1)];
	// Get the title of this outline box
	thistitle = firstOB << getTitle;
	// Save as HTML
	firstOB << saveHTML("$DESKTOP/"||thistitle);
	);

View solution in original post

5 REPLIES 5
Highlighted
ian_jmp
Staff

Re: How to Save Group By Charts Individually

Here's an example you should be able to adapt:

NamesDefaultToHere(1);

// Get some data
dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Run the platform. NB: ccb is a list, because of teh use of the 'By' variable
ccb = dt << Control Chart Builder(
						Show Control Panel( 0 ),
						Show Limit Summaries( 0 ),
						Show Capability( 0 ),
						Variables( Y( :height ) ),
						By( :sex)
					);

// Save the report for each level of the 'By' variable
for(c=1, c<=NItems(ccb), c++,
	// Get the current report layer
	thisrep = Report(ccb[c]);
	// Get the first outline box
	firstOB = thisrep[OutlineBox(1)];
	// Get the title of this outline box
	thistitle = firstOB << getTitle;
	// Save as HTML
	firstOB << saveHTML("$DESKTOP/"||thistitle);
	);

View solution in original post

Highlighted
LeeP
Level III

Re: How to Save Group By Charts Individually

I've tried the following, but it is not running properly:

current data table(ppn);

ppnP = ppn << Control Chart Builder(
	Sample Label( :ReleaseMonth ),
	Phase( :Phase ),
	Sample Size( :Name( "Sum-Total" ) ),
	KSigma( 3 ),
	Chart Col( :OnTimePct, P( Phase Level( "1" ), Phase Level( "2" ) ) ),
	By( :name )
);

// Save the report for each level of the 'By' variable
For( c = 1, c <= N Items( ccb ), c++, 
// Get the current report layer
	thisrep = Report( ccb[c] );
// Get the first outline box

	firstOB = thisrep[Outline Box( 1 )];
// Get the title of this outline box
	thistitle = firstOB << getTitle;
// Save as HTML
	firstOB << saveHTML( "$DESKTOP/" || thistitle );
);

 

I get a single report like the following (note: I blacked out info) and nothing is saved as html to the desktop directory. I'm creating P charts, so don't know if that is an issue with this process.

JMP3.jpg

Highlighted
ian_jmp
Staff

Re: How to Save Group By Charts Individually

I doubt it's an issue with the type of chart. But I notice that you have assigned the reference to the multiple p charts from Control Chart Builder to 'ppnP', but the subsequent code still refers to 'ccb' (as I used in the example).

Highlighted
LeeP
Level III

Re: How to Save Group By Charts Individually

Good catch on "ccb". That was part of the issue. The other problem was using "Control Chart Builder". I changed it to just "Control Chart" and it works. The new issue is the file name that is generated. I see you used:

thistitle = firstOB << getTitle;

This gives me a title name of: "Control Chart name=XXXXXXX"

1. I'm guessing that by using saveHTML, I could append .html since it is being saved without an extension.

2. How can I get get just the XXXXXX part? Would I have to know in advance that it will always be "Control Chart <Grouped by Field Name>=" and then manipulate that string value, or is there a simpler way? Are there string manipulation functions in JMP?

Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: How to Save Group By Charts Individually


@LeeP wrote:

Are there string manipulation functions in JMP?


There are many. Here's a good start:

 

JSL Character String Functions 

If you learn only one Formula Editor function, Word() is the one 

-Jeff
Article Labels

    There are no labels assigned to this post.