cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lala
Level VII

How to add text to a graph after drawing using JSL?

Add the text "txt1" at the top left of the image coordinates (100,100)

Thanks!

2023-11-08_7-14-18.png

dt = Current Data Table();
P1 = dt << Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :age ), Y( :sex ) ),
	Elements( Heatmap( X, Y, Legend( 2 ) ) )
	//, Text( Center Justified, {100, 100  }, "txt1"); ??
);
11 REPLIES 11
lala
Level VII

Re: How to add text to a graph after drawing using JSL?

Dispatch(
	{},
	"Graph Builder",
	FrameBox( 2 ),
	{Add Graphics Script(
		9,
		Description( "" ),
		Text( Center Justified, {20, 70}, Char( gm ) || "——" || na9 )
	)}
),
txnelson
Super User

Re: How to add text to a graph after drawing using JSL?

There are a couple of ways to do what you want.  You can use Annotation or you can use a Graphic Script. 

txnelson_0-1699413894852.png

With Annotation, you specify the Text and the location of the Text Box.  In the JSL below, I added the Annotation within the definition of the Graph Builder JSL.  As can be seen, the Text Box location is determined by  what I remember as being the pixel location within the frame box.

Add Graphics Script usage, uses the actual X and Y axis values for it's location.  However, this is not real straight forward with your graph.  Since both axes are not Continuous columns, but rather are Ordinal and Nominal, JMP assigns  integer values to each of the levels found in the data, starting with 0.  Therefore since there are 6 levels of Age, the X axis goes from 0 to 5.  Therefore, when referencing the X value in the Text() function, it needs to be within the range of -.5 to 5.5 to be visible.  Similarly, the  Y axis value needs to be within -.5 to 1.5. If a column used in the graph is Continuous, the actual values of the data are used in the X,Y location specification.  For this example, I used a << Add Graphics Script() as an after Platform Execution to add the graphic to the Frame Box().  See below.

gb = Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :age ), Y( :sex ) ),
	Elements( Heatmap( X, Y, Legend( 2 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			{Add Text Annotation(
				Text( "Using Annotation" ),
				Fixed Size( 0 ),
				Text Box( {169, 137, 224, 200} ),
				Font( "Segoe UI", 14, "Bold" ),
				Filled( 0 )
			), Add Text Annotation(
				Text( "" ),
				Fixed Size( 0 ),
				Text Box( {269, 171, 286, 179} ),
				Filled( 0 )
			)}
		)
	)
);
Report( gb )[framebox( 1 )] << add graphics script(
	Text Font( "Arial", 14, "Bold" );
	Text( Center Justified, {1.5, .90}, "Using Add Graphics" );
);

 

Jim
lala
Level VII

Re: How to add text to a graph after drawing using JSL?

I still haven't learned how to add text to my drawings.
For example, how to add text from the top left corner 100, 100?

Thanks Experts!

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
p1 = dt << Graph Builder(
	Size( 507, 440 ),
	Show Control Panel( 0 ),
	Show Legend( 0 ),
	Variables( X( :weight ), Y( :height ), Color( :sex ) ),
	Elements( Bar( X, Y, Legend( 5 ), Bar Style( "Needle" ), Response Axis( "X" ) ) ),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Label Row(
				{Automatic Tick Marks( 0 ), Show Major Labels( 0 ), Show Major Ticks( 0 ),
				Show Minor Ticks( 0 )}
			)}
		),
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Label Row(
				{Automatic Tick Marks( 0 ), Show Major Labels( 0 ), Show Major Ticks( 0 ),
				Show Minor Ticks( 0 )}
			)}
		),
		Dispatch( {}, "graph title", TextEditBox, {Set Text( "Big Class" )} ),
		Dispatch( {}, "X title", TextEditBox, {Hide( 1 )} ),
		Dispatch( {}, "Y title", TextEditBox, {Hide( 1 )} )
	)
);

2023-11-27_07-27-42.png

txnelson
Super User

Re: How to add text to a graph after drawing using JSL?

Below is a modification to your script that adds an annotation to the graph by placing a text box() at 100,100, with the text being "Big Class".  The annotation functions use pixels to place the values.

txnelson_1-1701056423217.png

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

Graph Builder(
	Size( 776, 457 ),
	Show Control Panel( 0 ),
	Show Legend( 0 ),
	Variables( X( :weight ), Y( :height ), Color( :sex ) ),
	Elements(
		Bar( X, Y, Legend( 5 ), Bar Style( "Needle" ), Response Axis( "X" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Label Row(
				{Automatic Tick Marks( 0 ), Show Major Labels( 0 ),
				Show Major Ticks( 0 ), Show Minor Ticks( 0 )}
			)}
		),
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Label Row(
				{Automatic Tick Marks( 0 ), Show Major Labels( 0 ),
				Show Major Ticks( 0 ), Show Minor Ticks( 0 )}
			)}
		),
		Dispatch( {}, "graph title", TextEditBox, {Set Text( "Big Class" )} ),
		Dispatch( {}, "X title", TextEditBox, {Hide( 1 )} ),
		Dispatch( {}, "Y title", TextEditBox, {Hide( 1 )} ),
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			Add Text Annotation(
				Text( "Big Class" ),
				Fixed Size( 0 ),
				Text Box( {100,100, 150, 150} ),
				Filled( 0 )
			)
		)
	)
);

 

Jim
lala
Level VII

Re: How to add text to a graph after drawing using JSL?

Text added through the text box cannot be saved elsewhere with the original image.

jthi
Super User

Re: How to add text to a graph after drawing using JSL?

What do you mean by saving elsewhere with the original image?

 

Text seems to be saved with this picture just fine?

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb = dt << Graph Builder(
	Size(776, 457),
	Show Control Panel(0),
	Show Legend(0),
	Variables(X(:weight), Y(:height), Color(:sex)),
	Elements(Bar(X, Y, Legend(5), Bar Style("Needle"), Response Axis("X"))),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Label Row({Automatic Tick Marks(0), Show Major Labels(0), Show Major Ticks(0), Show Minor Ticks(0)})}
		),
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Label Row({Automatic Tick Marks(0), Show Major Labels(0), Show Major Ticks(0), Show Minor Ticks(0)})}
		),
		Dispatch({}, "graph title", TextEditBox, {Set Text("Big Class")}),
		Dispatch({}, "X title", TextEditBox, {Hide(1)}),
		Dispatch({}, "Y title", TextEditBox, {Hide(1)}),
		Dispatch(
			{},
			"Graph Builder",
			FrameBox,
			Add Text Annotation(Text("Big Class"), Fixed Size(0), Text Box({100, 100, 150, 150}), Filled(0))
		)
	)
);

pic = gb << Get Picture;

gb << Close Window;
Close(dt, no save);

nw = new window("",
	pic
);

pic << Save Picture("$TEMP/textbox.png", "PNG");

Open("$TEMP/textbox.png");
-Jarmo
lala
Level VII

Re: How to add text to a graph after drawing using JSL?

I see

gb << Get Picture;
Need to cut the excess.

2023-11-27_15-06-43.png

 

txnelson
Super User

Re: How to add text to a graph after drawing using JSL?

You can delete the axis settings and then copy the picture. Go interactively into the Axis Settings, and then you can delete the axes.  Then Save the Script to see what the JLS is to delete the axes. 

Jim
txnelson
Super User

Re: How to add text to a graph after drawing using JSL?

Where are you attempting to save the image to?  The below JSL saves to multiple places, with the added text being saved with the image

report(gb)<<journal;

report(gb)<<save presentation("$TEMP/jmp_example.pptx" );
Open( "$TEMP/jmp_example.pptx" );

report(gb)[framebox(1)]<<journal;

report(gb) << Save Interactive HTML( "$TEMP/jmp_example.html" );
open( "$TEMP/jmp_example.html");
Jim