cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Graph builder element loop function

SING
Level II

How can i use loop function for multiple position definition?

If separate like below it work:

Eval(
			Substitute(
			Expr(
				gb = cdt << Graph Builder(
					Size( 600, 800 ),
					Show Control Panel( 0 ),
					vvv,
					Elements(Position( 1, 1 ),
						Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 3 ) ),
						Smoother( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 4 ) )
					),
					Elements(
                    Position( 2, 1 ),
                    Box Plot( X, Y, Outliers( 0 ) ),
                    Points( X, Y ),
                    Bar( X, Y, Bar Style( "Float" ), Label( "Label by Value" ) ),
                    Legend( 6 )
                ),
                Elements(
                    Position( 2, 2 ),
                    Box Plot( X, Y, Outliers( 0 ) ),
                    Points( X, Y ),
                    Bar( X, Y, Bar Style( "Float" ), Label( "Label by Value" ) ),
                    Legend( 7 )
                ),
                Elements(
                    Position( 2, 3 ),
                    Box Plot( X, Y, Outliers( 0 ) ),
                    Points( X, Y ),
                    Bar( X, Y, Bar Style( "Float" ), Label( "Label by Value" ) ),
                    Legend( 8 )
                )
            )
        ),
        Expr( vvv ),
        Name Expr( var expr )
    )
);

But if using loop like this it's only have bar, what's missing in this code?

Eval(
			Substitute(
			Expr(
				gb = cdt << Graph Builder(
					Size( 600, 800 ),
					Show Control Panel( 0 ),
					vvv,
					Elements(Position( 1, 1 ),
						Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 3 ) ),
						Smoother( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 4 ) )
					),
					For( j = 1, j <= n_mydatecol, j++,
						Elements(
							Position( 2, j ),
							Box Plot( X, Y, Outliers( 0 ) ),
							Points( X, Y ),
							Bar( X, Y, Bar Style( "Float" ), Label( "Label by Value" ) ),
							Legend(eval( 5 + j ))
						),
					),
				)
			),
			Expr( vvv ),
			Name Expr( var expr )
		)
	);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User


Re: Graph builder element loop function

I'm not sure what you are plotting, but it might (or might not) work. Here I'm using Add Element to add bar chart to X axis 2 and Y axis 1 and 2

Names Default To Here(1); 

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

gb = dt << Graph Builder(
	Size(528, 454),
	Show Control Panel(0),
	Variables(X(:height), X(:sex), Y(:name), Y(:weight)),
	Elements(Position(1, 1), Points(X, Y, Legend(20))),
	Elements(
		Position(1, 2),
		Points(X, Y, Legend(5)),
		Smoother(X, Y, Legend(6)),
		Line Of Fit(X, Y, Legend(8))
	),
	Elements(Position(2, 1), Points(X, Y, Legend(19))),
	Elements(Position(2, 2), Points(X, Y, Legend(18)))
);

gb << Add Element(2, 1, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});
gb << Add Element(2, 2, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});

jthi_0-1742535061828.png

 

-Jarmo

View solution in original post

9 REPLIES 9
jthi
Super User


Re: Graph builder element loop function

You could build the elements expressions separately and then evaluate it inside graph builder expression. Or in some cases it might be easier if you use << Add Element

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb = Graph Builder(Variables(X(:height), Y(:weight)), Elements(Points(X, Y), Smoother(X, Y)));
Wait(0.5);
gb << Add Element(1, 1, {Type("Line Of Fit"), X, Y, Degree("Quadratic")});
-Jarmo
SING
Level II


Re: Graph builder element loop function

my chart want to be like this, do I need to define the position?

SING_0-1742456555126.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

jthi
Super User


Re: Graph builder element loop function

Add element does allow you setting X and Y position. Did you try if it would work for your use case?

-Jarmo
SING
Level II

Re: Graph builder element loop function

Hello Jarmo,

Try to use the code below, but still only show box plot, how can i show the bar and label.

SING_1-1742456919072.png

 

Eval(
Substitute(
Expr(
gb = cdt << Graph Builder(
Size( 1200, 800 ),
Show Control Panel( 0 ),
vvv,
Elements(
Position( 1, 1 ),
Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 3 ) ),
Smoother( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 4 ) )
)
);

// Loop to add repetitive elements
For( i = 2, i <= 10, i++,
gb << Add Elements(
Position( 2, i ),
Box Plot( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 2 * i + 1 ) ),
Bar( X, Y, Legend( 2 * i + 2 ), Bar Style( "Float" ), Label( "Label by Value" ), Label Format( "Fixed Dec", 5, 2 ) )
);
);
),
Expr( vvv ),
Name Expr( var expr )
)
);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

jthi
Super User


Re: Graph builder element loop function

I will have to create example data (or find appropriate one) and re-create the graph so it will take some time

-Jarmo
jthi
Super User


Re: Graph builder element loop function

I can see all the images have changed to something totally different they were earlier... I'm not sure how well the scripts provided to correspond to those new images. Which columns would have to be added dynamically and where?

 

Graph builder script for this

jthi_0-1742487233052.png

looks something like this

Names Default To Here(1); 

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

gb = dt << Graph Builder(
	Size(528, 454),
	Show Control Panel(0),
	Variables(X(:height), X(:sex), Y(:weight)),
	Elements(
		Position(1, 1),
		Points(X, Y, Legend(5)),
		Smoother(X, Y, Legend(6)),
		Line Of Fit(X, Y, Legend(8))
	),
	Elements(
		Position(2, 1),
		Points(X, Y, Legend(18)),
		Bar(X, Y, Legend(19), Bar Style("Float"), Label("Label by Value"))
	)
);

If you have a plot like this and you wish to add float bar chart to it to the right side with points

jthi_1-1742487267356.png

You can use add element

gb << Add Element(2, 1, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});
View more...
Names Default To Here(1); 

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

gb = dt << Graph Builder(
	Size(528, 454),
	Show Control Panel(0),
	Variables(X(:height), X(:sex), Y(:weight)),
	Elements(
		Position(1, 1),
		Points(X, Y, Legend(5)),
		Smoother(X, Y, Legend(6)),
		Line Of Fit(X, Y, Legend(8))
	),
	Elements(
		Position(2, 1),
		Points(X, Y, Legend(18))
	)
);

gb << Add Element(2, 1, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});

 

-Jarmo
SING
Level II


Re: Graph builder element loop function

Hi Jarmo,
Thanks for the helping, it can work went the y axis only have one, but what I want is if their have multiple y axis, can i still using loop function to have the element with box plot and bar? I had tried like the first one, but it only showed box plot without bars.

jthi
Super User


Re: Graph builder element loop function

I'm not sure what you are plotting, but it might (or might not) work. Here I'm using Add Element to add bar chart to X axis 2 and Y axis 1 and 2

Names Default To Here(1); 

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

gb = dt << Graph Builder(
	Size(528, 454),
	Show Control Panel(0),
	Variables(X(:height), X(:sex), Y(:name), Y(:weight)),
	Elements(Position(1, 1), Points(X, Y, Legend(20))),
	Elements(
		Position(1, 2),
		Points(X, Y, Legend(5)),
		Smoother(X, Y, Legend(6)),
		Line Of Fit(X, Y, Legend(8))
	),
	Elements(Position(2, 1), Points(X, Y, Legend(19))),
	Elements(Position(2, 2), Points(X, Y, Legend(18)))
);

gb << Add Element(2, 1, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});
gb << Add Element(2, 2, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});

jthi_0-1742535061828.png

 

-Jarmo
SING
Level II


Re: Graph builder element loop function

It works, and I try like this.

Thanks a lot

Eval(
			Substitute(
			Expr(
				gb = cdt << Graph Builder(
					Size( 600, 800 ),
					Show Control Panel( 0 ),
					vvv,
					Elements(Position( 1, 1 ),
						Points( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 3 ) ),
						Smoother( X, Y( 1 ), Y( 2 ), Y( 3 ), Legend( 4 ) )
					),
					);
				For( i = 1 , i <= n_mymetric , i++, 
					gb << Add Element(2, i, {Type("Bar"), X, Y, Bar Style("Float"), Label("Label by Value")});
				),
			),
			Expr( vvv ),
			Name Expr( var expr )
		)
	);