cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
ivomdb
Level III

How to save each graph from graph builder into an image file with the title from the List array

Hello all,

 

I have trying to find a away of saving my results into a pptx. template and realized that I should first save each result into a file to then compile into a template report.

According the following post:

https://community.jmp.com/t5/Discussions/the-graph-size-exported-to-pptx-Save-Presentation/m-p/72135...

 

However, I have not been able to find a away of naming my files according to the List that is created under the loop. I am using the following Big Class example:

 

dt2 = Open( "$SAMPLE_DATA\Big Class.JMP" );

win = New Window( "Graphs", lub = Lineup Box( N Col( 2 ) ) );

ages = (Associative Array( Column( dt2, "age" ) ) << Get keys);

For( i = 1, i <= N Items( ages ), i++,
	dt2 << select where( :age == ages[i] );
	dt = dt2 << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
	lub << append(
		gb = dt << Graph Builder(
			Variables( X( :weight ), Y( :height ), Wrap( :age, N View Levels( 1 ) ) ),
			Elements( Points( X, Y, Legend( 7 ) ), Smoother( X, Y, Legend( 9 ) ) ),
			Local Data Filter(
				Close Outline( 1 ),
				Add Filter(
					columns( :age ),
					Where( :age == ages[i] ),
					Display( :age, Size( 224, 126 ), List Display )
				)
			)
		);
		Report( gb )[AxisBox( 2 )] << Min( 0 );
		
		gb<< save picture(Eval Insert("C:\....\BigClass^i^.png"));););

Is there anyone that knows how to do this?

 

I have tried using the below instead but it does not work.

gb << Save Picture( "C:\BigClass_" || Ages[i] ||".jpg", JPEG );

Do I need to create a different String/List for this? Any guidance is much appreciated.

 

Thanks

9 REPLIES 9
XanGregg
Staff

Re: How to save each graph from graph builder into an image file with the title from the List array

Does "gb << Make Into Data Table()" help? It creates a new data table with a column of images.

ivomdb
Level III

Re: How to save each graph from graph builder into an image file with the title from the List array

@XanGregg

How would you then refereence each table ? How would you then save each table into a picture with the name of the List? 

 

Could you show how you would do this under this Big Class  example?

 

Thanks

 

XanGregg
Staff

Re: How to save each graph from graph builder into an image file with the title from the List array

I was thinking of something like the following, but now I realize it's probably not what you want since it doesn't capture the axes.

 

dt2 = Open( "$SAMPLE_DATA\Big Class.JMP" );

gb = dt2 << Graph Builder(
	Size(800, 600),
		Variables( X( :weight ), Y( :height ), Wrap( :age ) ),
		Elements( Points( X, Y ), Smoother( X, Y ) )
	);
Report( gb )[AxisBox( 2 )] << Min( 0 );

dt = gb << make into data table();
for each row(dt, 
	img = :graph;
	img << save image(Eval Insert("$DOCUMENTS/BigClass^char(:age)^.png"));
);
ivomdb
Level III

Re: How to save each graph from graph builder into an image file with the title from the List array

It definitely works but is not what I want. I would like to have the image as when saving picture <<
gzmorgan0
Super User (Alumni)

Re: How to save each graph from graph builder into an image file with the title from the List array

You need a Char() function around Ages[i]. The values of your associative array Ages are numeric.  Note the script below is writing to the c:\temp\ directory. Also the commented statement will work as well.   You should close your Append() statement before the save  statement.

 

dt2 = Open( "$SAMPLE_DATA\Big Class.JMP" );

win = New Window( "Graphs", lub = Lineup Box( N Col( 2 ) ) );

ages = (Associative Array( Column( dt2, "age" ) ) << Get keys);

For( i = 1, i <= N Items( ages ), i++,
	dt2 << select where( :age == ages[i] );
	dt = dt2 << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
	lub << append(
		gb = dt << Graph Builder(
			Variables( X( :weight ), Y( :height ), Wrap( :age, N View Levels( 1 ) ) ),
			Elements( Points( X, Y, Legend( 7 ) ), Smoother( X, Y, Legend( 9 ) ) ),
			Local Data Filter(
				Close Outline( 1 ),
				Add Filter(
					columns( :age ),
					Where( :age == ages[i] ),
					Display( :age, Size( 224, 126 ), List Display )
				)
			)
		);
	);
	Report( gb )[AxisBox( 2 )] << Min( 0 );
		
	//gb<< save picture(Eval Insert("C:\temp\BigClass^i^.png"));
gb << Save Picture( "C:\temp\BigClass_" || char(Ages[i]) ||".jpg", JPEG ); );
 

 

ivomdb
Level III

Re: How to save each graph from graph builder into an image file with the title from the List array

@gzmorgan0

Thanks for the tip. It works under this example for Big Class. However, it does not work on my scrypt.

I have tried both commands and only the first works for my script but only replaces ^i^ as a number and not Name/Character which is what I have as a List. The second command works fine for the Big Class example so may be Char() is not applicable for Names?

gb<< save picture(Eval Insert("C:\temp\BigClass^i^.png"));

//and also

gb << Save Picture( "C:\temp\BigClass_" || char(Ages[i]) ||".jpg", JPEG );
);

I have also tried using the Char() function under the first line of command but it does not work as the "||" does not seem to work for the Eval Insert().

 

gb<< save picture(Eval Insert("C:\temp\^i^.png") ||Char(Ages[i])||".jpg",JPEG););

DO you know how to get around this ?

 

gzmorgan0
Super User (Alumni)

Re: How to save each graph from graph builder into an image file with the title from the List array

Your last post had

gb<< save picture(Eval Insert("C:\temp\^i^.png") ||Char(Ages[i])||".jpg",JPEG););

Please look at your syntax. For i=1 where Ages[i] = 12, this would produce the string "C:\temp\1.png12.jpg" .

 

gb<< save picture("C:\temp\Age_" ||Char(Ages[i])||".jpg",JPEG););

For i=1 where Ages[i] = 12, this would produce the string "C:\temp\Age_12.jpg"

 

Your original example used unique values of the column :age as your list.  If the save is not working, and it is not due to poor syntax maybe the values in your list have symbols that cannot be a valid Windows name. I did not open your referenced link until just now. If you are using  p3icli to create pptx, you can use p3icli commands for title and captions for complex names or comments. I have used this method to write reports to audit control limits:

  • create a list of p3icli commands, I called cmdlist, then for each i insert into cmdlist the p3icli commands for
  • for insert new slide or duplicate template
  • a command for a complex title that provides context parameter information, data dates, etc. about the chart to be displayed
  • a command to insert the picture using simple names like fid1 or fid2
  • a command for a caption based upon the analyses, whether limits are too loose or too tight etc.

I wrote this outline as an illustration of using p3icli title and caption options instead of using saved file names.

If you need to use an alternative for p3icli, this is not the proper forum, please send a private message.

 

After reviewing your list, you do not find unusual symbols like @  # % ( ) - ^ in your list, then you need to provide a snippet of your actual JSL code and the error message.

ivomdb
Level III

Re: How to save each graph from graph builder into an image file with the title from the List array

@gzmorgan0

Thanks for the repply. 

I am trying to use JSL up until the point I need to create the report in pptx. The reason for saving the graphs according to the list name is because I need to create a report for each element of this list. 

I have put the JSL script below. The script as it is works but it does not save the graphs with its correspondent list name, It only saves each graph as sample_1; sample_2...etc. For example the name of my sample_1 is "EH3", however, the names will change every month and so ideally I would need it to get the name from the list. 

I still have to add a summary tabulate for each Sample[i] and add it together with the graph to pptx. Is this possible?

 

win = New window("Graphs", lub = Lineup Box (Ncol(3)));

//selecting the list of samples or variables for which a graph is required
Samples = (Associative Array(Column (dt4, "Sample"))<<Get keys);

//Loop through the list to generate the graphs
For (i = 1, i<= N items (Samples), i++,
dt4<<select where (:Sample==Samples[i]);
dt5=dt4<<subset(invisible,selected rows(1),selected column(0));

lub<<Append(
gb=dt5 << Graph Builder(
	Size( 894, 625 ),
	Legend Position( "Bottom" ),
	Show Title( 0 ),
	Show Control Panel( 0 ),
	Variables(
		X( :Days ),
		Y( :Model Growth rate ),
		Y( :Growth rate, Position( 1 ) ),
		Group X( :Sample, Show Title( 0 ), N View Levels( 1 ) )
	),
	Elements(
		Points( X, Y( 2 ), Legend( 14 ), Jitter Limit( 1.1193 ) ),
		Smoother( X, Y( 1 ), Legend( 15 ), Lambda( 0.0000146251389195779 ) )
	),
	Local Data Filter(
			Close Outline( 1 ),
			Add Filter(
				columns( :Sample ),
				Where( :Sample == Samples[i] ),
				Display( :Sample, Size( 224, 126 ), List Display )
			) 
	), SendToReport(
		Dispatch(
			{},
			"Days",
			ScaleBox,
			{Min( 0 ), Max( 21 ), Inc( 1 ), Minor Ticks( 1 ),
			Label Row(
				{Inside Ticks( 1 ), Set Font( "Calibri" ), Set Font Size( 14 )}
			)}
		),
		Dispatch(
			{},
			"Model Growth rate",
			ScaleBox,
			{Inc( 50 ), Minor Ticks( 0 ),
			Label Row(
				{Inside Ticks( 1 ), Set Font( "Calibri" ), Set Font Size( 14 )}
			)}
		),
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				14,
				Level Name( 0, "Experimental", Item ID( "Growth rate", 1 ) ),
				Properties( 0, {Marker Size( 5 )}, Item ID( "Growth rate", 1 ) )
			), Legend Model(
				15,
				Level Name( 0, "Model", Item ID( "Smooth(Model Growth rate", 1 ) ),
				Properties(
					0,
					{Line Color( 32 ), Line Width( 3 )},
					Item ID( "Smooth(Model Growth rate)", 1 )
				)
			)}
		),
		Dispatch(
			{},
			"X title",
			TextEditBox,
			{Set Font( "Calibri" ), Set Font Size( 14 )}
		),
		Dispatch(
			{},
			"Y title",
			TextEditBox,
			{Set Font( "Calibri" ), Set Font Size( 14 ),
			Set Text( "Growth rate (g/s)" )}
		),
		Dispatch( {}, "Graph Builder", Outlinebox, {Set Title( "" )})));
	Report(gb)[Axisbox(2)]<<Min(0);
	
	
		gb<< save picture(Eval Insert("C:\Users\ioliveira\Desktop\data\sample_^i^.png"));););

	
(win << XPath("//OutlineBox[@helpKey='Data Filter']") ) << Visibility("collapse");	

 

 

Phil_Kay
Staff

Re: How to save each graph from graph builder into an image file with the title from the List array

I can't directly answer your question but just a couple of thoughts around the approach. You might want to explore these via the point'n'clikc before looknig at scripting.

 

1. You might want to use the Page role in Graph Builder because this creates a separate plot with axes for each level of the variable in Page.

 

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

Graph Builder(
	Size( 518, 2948 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ), Page( :age ) ),
	Elements( Points( X, Y, Legend( 5 ) ), Smoother( X, Y, Legend( 6 ) ) )
);

 

2. Might be worth thinking about how you can use the save as powerpoint capability. From any report: File > Save As > Save as type: Powerpoint Presentation. Save Presentation() is the JSL function.

 

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
biv = bivariate( y( :weight ), x( :height ) );
rbiv = biv << report;
rbiv << Save Presentation( "$TEMP/jmp_example.pptx" );
Open( "$TEMP/jmp_example.pptx" );

 

Hope that helps.

Regards,

Phil