cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
BabyDoragon
Level I

How can I annotate the background with different colors across different Y-axes?

The following JSL can annotate the region of 100 to 120 on the X-axis with a different color, but it cannot span across different Y-axes. How can I modify it to annotate different variable on Y-axes with different background colors for different variables?

BabyDoragon_0-1726834635856.png

 

 

Names Default To Here(1);

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

gb = dt << Graph Builder(
	Variables(X(:weight), Y(:height),Y(:age)),
	Elements(Points(X, Y, Legend(3))),
	SendToReport(

		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Add Ref Line(100, "Solid", "blue", "", 5),
			Add Ref Line(120, "Solid", "blue", "", 5)}
		)
	)
);

rep = gb << report;
framebox = rep[frame box(1)];
framebox << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Gray");
	Rect(100, Y Origin() + Y Range(), 120, Y Origin() , 1)
);
2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

You have multiple FrameBoxes when you have multiple axis (or groups or wraps or pages), so you can for example add separate graphic script to each of them. Simplified version below

Names Default To Here(1);

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

gb = dt << Graph Builder(
	Variables(X(:weight), Y(:height), Y(:age)),
	Elements(Points(X, Y, Legend(3)))
);

rep = gb << report;
fbs = rep << XPath("//FrameBox");

fbs[1] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Gray");
	Rect(100, Y Origin() + Y Range(), 120, Y Origin(), 1);
);

fbs[2] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Green");
	Rect(100, Y Origin() + Y Range(), 120, Y Origin(), 1);
);

jthi_0-1726835169724.png

 

-Jarmo

View solution in original post

jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

If I remember correctly... (currently) easiest method is to read it from the data table using Summary table or Summarize.

-Jarmo

View solution in original post

9 REPLIES 9
jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

You have multiple FrameBoxes when you have multiple axis (or groups or wraps or pages), so you can for example add separate graphic script to each of them. Simplified version below

Names Default To Here(1);

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

gb = dt << Graph Builder(
	Variables(X(:weight), Y(:height), Y(:age)),
	Elements(Points(X, Y, Legend(3)))
);

rep = gb << report;
fbs = rep << XPath("//FrameBox");

fbs[1] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Gray");
	Rect(100, Y Origin() + Y Range(), 120, Y Origin(), 1);
);

fbs[2] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Green");
	Rect(100, Y Origin() + Y Range(), 120, Y Origin(), 1);
);

jthi_0-1726835169724.png

 

-Jarmo
BabyDoragon
Level I

Re: How can I annotate the background with different colors across different Y-axes?

Additional Question: How can I draw a color box if the X-axis is of data type "text"?

For example, I want to mark the range from TIM to JOE with a specific color.

Names Default To Here(1);

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

gb = dt << Graph Builder(
	Variables(X(:name), Y(:height), Y(:age)),
	Elements(Points(X, Y, Legend(3)))
);

rep = gb << report;
fbs = rep << XPath("//FrameBox");

fbs[1] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Gray");
	Rect("TIM", Y Origin() + Y Range(), "JOE", Y Origin(), 1);
);

fbs[2] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Green");
	Rect("TIM", Y Origin() + Y Range(), "JOE", Y Origin(), 1);
);
jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

You have to figure out the correct x-axis values and then utilize those

Names Default To Here(1);

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

gb = dt << Graph Builder(
	Variables(X(:name), Y(:height), Y(:age)),
	Elements(Points(X, Y, Legend(3)))
);

rep = gb << report;
fbs = rep << XPath("//FrameBox");

fbs[1] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Gray");
	Rect(17, Y Origin() + Y Range(), 37, Y Origin(), 1);
);

fbs[2] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Green");
	Rect(17, Y Origin() + Y Range(), 37, Y Origin(), 1);
);

This can be easy or sometimes very difficult, but you can get the idea by checking X-axis settings and labels

jthi_0-1728561523500.png

 

-Jarmo
BabyDoragon
Level I

Re: How can I annotate the background with different colors across different Y-axes?

How can I use JSL to read the mapping of LABEL and VALUE in the current X-axis? I can't find a method to read the LABEL and corresponding VALUE on the current X-axis.

I would like to use MATCH on the text label to obtain the VALUE, and then highlight the specific range of values with a colored box.

jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

If I remember correctly... (currently) easiest method is to read it from the data table using Summary table or Summarize.

-Jarmo
BabyDoragon
Level I

Re: How can I annotate the background with different colors across different Y-axes?

I would like to mark colors on the X-axis in accordance with the user-selected region. However, the X-axis on the chart changes due to the user's use of a local data filter. Since the text form of the X-axis is variable, I cannot specify a fixed value and label correspondence. I hope to directly access the labels and values on the X-axis of the chart or be able to determine the corresponding value and label on the X-axis based on the user's selection on the local data filter. As shown in the script below, I would like to allow the user to select the local data filter and additionally choose the X-axis to be marked with colors. If it is not possible to obtain the currently displayed items on the X-axis of the graph or the selected results on the local data filter, it will not be possible to obtain the corresponding values and labels smoothly. Is there any way to achieve this?"
Names Default To Here(1);

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

gb = dt << Graph Builder(
	Variables(X(:name), Y(:height), Y(:age)),
	Elements(Points(X, Y, Legend(3))),
	Local Data Filter(
		Add Filter(
			columns( :name ),
			Where(
				:name == {"ALFRED", "ALICE", "AMY", "BARBARA", "CAROL", "CHRIS",
				"CLAY"}
			),
			Display( :name, N Items( 15 ), Find( Set Text( "" ) ) )
		)
	),
);

rep = gb << report;
fbs = rep << XPath("//FrameBox");

fbs[1] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Gray");
	Rect(2, Y Origin() + Y Range(), 4, Y Origin(), 1);
);

fbs[2] << Add Graphics Script(
	Transparency(0.5);
	Fill Color("Green");
	Rect(2, Y Origin() + Y Range(), 4, Y Origin(), 1);
);
jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

If you have local filter to manage it will most likely get more complicated. Which range do you wish to color? What happens when user filters that out or one end of it? 

-Jarmo
BabyDoragon
Level I

Re: How can I annotate the background with different colors across different Y-axes?

Yes, it does become more complex with the presence of Local data filter. Therefore, I would like to know if there are any techniques to obtain the current items on the X-axis of the Graph or to read the selected options of the Local data filter in order to calculate the mapping table for the current Value and Label.

jthi
Super User

Re: How can I annotate the background with different colors across different Y-axes?

You can get different types of values from local data filter and then you can parse/utilize those

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Car Poll.jmp");
dist = dt << Distribution(
	Nominal Distribution(Column(:country))
);

ldf = dist << Local Data Filter(
	Add Filter(columns(:sex), Where(:sex == "Female")),
	Mode(Show(1), Include(1))
);

Show(ldf << get script, ldf << Get where clause, ldf << Get Filtered Rows);

jthi_0-1729059133994.png

Remember to check for the special case where no rows are being filtered

-Jarmo