Subscribe Bookmark RSS Feed

how to save graphs when using PAGE in graph builder JSL ?

vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

If I have used the "PAGE" function in graph builder and now I have multiple graphs on the same page, how do I get the graph builder graphs one by one in a loop to save it as png?

 

This is an example code from @Craige 

 

dt = Open( "$sample_data/big class.jmp" );
ages = Data Table( "big class" ) << Summary( Group( :age ), Freq( "None" ), Weight( "None" ) );
sexes = Data Table( "big class" ) << Summary( Group( :sex ), Freq( "None" ), Weight( "None" ) );
Delete Directory( "$temp/myPics" );
Create Directory( "$temp/myPics" );
For( iage = 1, iage <= N Rows( ages ), iage++,
thisAge = ages:age[iage];
For( isex = 1, isex <= N Rows( sexes ), isex++,
thisSex = sexes:sex[isex];
Eval(
Eval Expr(
gb = dt << Graph Builder(
Size( 508, 438 ),
Show Control Panel( 0 ),
Variables( X( :weight ), Y( :height ) ),
Elements( Points( X, Y, Legend( 5 ) ) ),
where( age == Expr( thisAge ) & sex == Expr( thisSex ) )
)
)
);
parentBox = (Report( gb ) << parent)<<parent;
picture = parentBox << getpicture;
picture << saveImage( "$temp/myPics/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png", "png" );
// optional: Open( "$temp/myPics/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png" );
gb << closewindow;
);
);
Close( ages, "nosave" );
Close( sexes, "nosave" );
Show( Files In Directory( "$temp/myPics" ) );

 

Thank you. 

1 ACCEPTED SOLUTION

Accepted Solutions
Wendy_Murphrey

Joined:

Jun 23, 2011

Solution

With Page(), the complete graphs are not stored in individual DisplayBoxes that can be saved to individual PNG files.  Exporting to a PowerPoint file would break up the pages.  Otherwise, you would need to use a Local Data Filter, Where(), or By().

Wendy

Wendy
9 REPLIES
Wendy_Murphrey

Joined:

Jun 23, 2011

Hello,

Personally, I would use a By() instead of Page() for this case because with a By, a list of Graph Builder objects is returned.  I can then loop through the list of objects to save each PNG file.  For example, 

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

gb = dt << Graph Builder(
	Size( 528, 454 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 3 ) ), Smoother( X, Y, Legend( 4 ) ) ),
	By( :age, :sex )
);

For( i = 1, i <= N Items( gb ), i++,
	fName = Report( gb[i] )[Outline Box( 1 )] << Get Title;
	Report( gb[i] )[Outline Box( 1 )] << Save Picture( "$TEMP/myPics/" || fName || ".png", "PNG" );
);

 

Hope this helps!

Wendy

Wendy
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Hi Wendy,

 

Thank you for theidea of using By. The reason I want PAGE function was , it gives me an option to lock the scales and I can display all , not just the one selected.

By any chance is there a way to access different graphs to plot using the PAGE function? It would b really helpful.

 

Thank you so much.

Wendy_Murphrey

Joined:

Jun 23, 2011

Solution

With Page(), the complete graphs are not stored in individual DisplayBoxes that can be saved to individual PNG files.  Exporting to a PowerPoint file would break up the pages.  Otherwise, you would need to use a Local Data Filter, Where(), or By().

Wendy

Wendy
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

I think I can work with that,
is it just a line of script to get the powerpoint?
Thank you Wendy
Wendy_Murphrey

Joined:

Jun 23, 2011

Yes, there is an example in the Scripting Index.  

  1. Click on the Help menu and select Scripting Index.  
  2. Enter Save Presentation in the search box.

The Scripting Index provides the syntax, a brief description, and an example script for Save Presentation. I have attached an image of the window for your convenience.

Good luck with your scripting project!

Wendy

 

Wendy
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

I made it work on the powerpoint with a loop. Thank you Wendy
stephen_pearson

Community Trekker

Joined:

Oct 6, 2014

A pptx file is just a disguised zip file. If you change the extension from .pptx to .zip (you may need to alter the folder settings in Windows to show known file extensions). Inside the zip file will be a folder called media which contains all the images.

melaniedrake

Staff

Joined:

May 30, 2014

Powerpoint works, though I'm not sure how you get the pictures out of powerpoint.

I've experimented and had some luck with saving as html. When you save a report as html, all the pictures are saved into a folder named gfx. If you keep saving the file over and over itself, the gfx folder doesn't get rewritten like the html page does, but all the pictures are just added to the same folder.

I've had several versions of this example script we werre working on in messages, and sometimes it saved each graph individually, and sometimes it didn't. With the current iteration, it seems to work. If it doesn't there's some code that does the save to powerpoint instead that's commented out. See if you can make this work with your more complex script. Note that the final html page will only have the very last graphbuilder report, not all of them. In the gfx folder, I get one picture for each graph and also one picture for each legend box - you'll have to cull them.

 

dt = Open( "$SAMPLE_DATA/Semiconductor Capability.jmp" );

unique lotid = Associative Array(dt:lot_id);
unique Wafer = Associative Array(dt:wafer);

currentid = unique lotid << First;
currentwafer = unique Wafer << First;

For( iwfr = 1, iwfr <= N Items( unique Wafer ), iwfr++, 

	nextwafer = unique Wafer << Next( currentwafer );

	Eval(
		Eval Expr(

			gb4 = dt << Graph Builder(
				Variables(
					X( :NPN1 ),
					Y( :PNP1 ),
					Page( :SITE ),
					Group X( :PNP2 ),
					Group Y( :NPN2 ),
					Color( :lot_id )
				),
				Elements( Treemap( X, Y, Legend( 24 ), Summary Statistic( "% of Total" ) ) ),
				where( Wafer == Expr( currentwafer ) ), 

				Display( :SITE, Size( 181, 153 ), List Display ), 
			)
		)
	);

	// powerpoint save
	//If( File Exists("$desktop/wow.pptx"), gb4 << Save Presentation( "$desktop/wow.pptx", "Append", "PNG" ),
	//	gb4 << Save Presentation( "$desktop/wow.pptx", "PNG" )
	//);
	
	// html save
	gb4 << Save HTML( "$desktop/wow.html", "PNG" );
	
	gb4 << Close Window;

	currentid = unique lotid << First;

);
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Thank you Melanie. I will try that.