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

Graph Builder Stacked Bar Chart

JMP 17 Attached is a simple data table containing monthly numbers of Total # of Parts, Total Fails, % Total Fails and then individual numbers for which Parameter failed. The stacked bar chart I want is Month on the X-axis and % Total Fails on Y-axis. Then I would like those bars to be stacked with the break out of which Parameter failed by the monthly percentage of each parameter. Below is a screen shot, see Fig 1, of something I drew up in ppt. I was unable to get this in Graph Builder. I tried stacking the data, manipulating columns but no go.

 

In summary I want the overall total % of failed parts on the Y-axis as a bar, then that bar showing the percentage of each parameter that failed for each month. Sample data table is attached below. Thank you.

Fig. 1

WoHNY_0-1695077305371.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Graph Builder Stacked Bar Chart

The chart that you want requires a change in the structure of your data table and the setting of some data table RowStates and Column States.

txnelson_0-1695094507351.png

 

The script below changes the structure of the data table and then draws the above final graph.  Everything in the script can be done interactively.  In fact, everything was done interactively and then I just took the script that JMP provided and copied into one final script.

Names Default to here(1);
dt = current data table();
dtStack = dt <<
Stack(
	columns(
		:Parm 1 # Fails, :Parm 2 # Fails, :Parm 3 # Fails, :Parm 1 % Fail,
		:Parm 2 % Fail, :Parm 3 % Fail
	),
	Source Label Column( "Parameter" ),
	Stacked Data Column( "Counts" ),
	Number of Series( 2 ),
	Contiguous
);

// Change the name of the column that has the % values
dtStack:Counts 2 << set name("Percent");

// Divide each row value for the percent column to conform
// to the percent values for a JMP column
for each row(
	:Percent = :Percent / 100;
);

// Change the display format for the percent column to 
// display a % sign in the values
dtStack:Percent << format("Percent", 7, 0);

// A column needs to be set to have the correct display values for
// the legend.  Also, the alphabetical ordering will determine the
// order of the subbar values.  So recode the column to meet those
// specifications
// Recode column: Parameter
Local( {dt},
	dt = dtStack;
	dt << Begin Data Update;
	dt << Recode Column(
		dt:Parameter,
		{Map Value(
			_rcOrig,
			{"Parm 1 # Fails", "3. Parm 1", "Parm 2 # Fails", "2. Parm 2",
			"Parm 3 # Fails", "1. Parm 3"},
			Unmatched( _rcNow )
		)},
		Update Properties( 1 ),
		Target Column( :Parameter )
	);
	dt << End Data Update;
);

// Label column: Percent to be used to label the graph
dtStack:Percent << Label( 1 );
// Label all rows to show which values from the percent column
// to label
dtStack << Select All Rows << Label(1);
dtStack << clear selection;
dtStack << invert row selection;

// Draw the graph
Graph Builder(
	Size( 528, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :Month ), Y( :Counts ), Overlay( :Parameter ) ),
	Elements(
		Bar( X, Y, Legend( 7 ), Bar Style( "Stacked" ), Label( "Label by Row" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties(
					0,
					{Fill Color( 73 )},
					Item ID( "1. Parm 3", 1 )
				),
				Properties(
					1,
					{Fill Color( 25 )},
					Item ID( "2. Parm 2", 1 )
				),
				Properties(
					2,
					{Fill Color( -7183127 )},
					Item ID( "3. Parm 1", 1 )
				)
			)}
		)
	)
);

Here is the restructured data table that was used to create the final chart.

txnelson_1-1695094803771.png

 

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Graph Builder Stacked Bar Chart

The chart that you want requires a change in the structure of your data table and the setting of some data table RowStates and Column States.

txnelson_0-1695094507351.png

 

The script below changes the structure of the data table and then draws the above final graph.  Everything in the script can be done interactively.  In fact, everything was done interactively and then I just took the script that JMP provided and copied into one final script.

Names Default to here(1);
dt = current data table();
dtStack = dt <<
Stack(
	columns(
		:Parm 1 # Fails, :Parm 2 # Fails, :Parm 3 # Fails, :Parm 1 % Fail,
		:Parm 2 % Fail, :Parm 3 % Fail
	),
	Source Label Column( "Parameter" ),
	Stacked Data Column( "Counts" ),
	Number of Series( 2 ),
	Contiguous
);

// Change the name of the column that has the % values
dtStack:Counts 2 << set name("Percent");

// Divide each row value for the percent column to conform
// to the percent values for a JMP column
for each row(
	:Percent = :Percent / 100;
);

// Change the display format for the percent column to 
// display a % sign in the values
dtStack:Percent << format("Percent", 7, 0);

// A column needs to be set to have the correct display values for
// the legend.  Also, the alphabetical ordering will determine the
// order of the subbar values.  So recode the column to meet those
// specifications
// Recode column: Parameter
Local( {dt},
	dt = dtStack;
	dt << Begin Data Update;
	dt << Recode Column(
		dt:Parameter,
		{Map Value(
			_rcOrig,
			{"Parm 1 # Fails", "3. Parm 1", "Parm 2 # Fails", "2. Parm 2",
			"Parm 3 # Fails", "1. Parm 3"},
			Unmatched( _rcNow )
		)},
		Update Properties( 1 ),
		Target Column( :Parameter )
	);
	dt << End Data Update;
);

// Label column: Percent to be used to label the graph
dtStack:Percent << Label( 1 );
// Label all rows to show which values from the percent column
// to label
dtStack << Select All Rows << Label(1);
dtStack << clear selection;
dtStack << invert row selection;

// Draw the graph
Graph Builder(
	Size( 528, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :Month ), Y( :Counts ), Overlay( :Parameter ) ),
	Elements(
		Bar( X, Y, Legend( 7 ), Bar Style( "Stacked" ), Label( "Label by Row" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties(
					0,
					{Fill Color( 73 )},
					Item ID( "1. Parm 3", 1 )
				),
				Properties(
					1,
					{Fill Color( 25 )},
					Item ID( "2. Parm 2", 1 )
				),
				Properties(
					2,
					{Fill Color( -7183127 )},
					Item ID( "3. Parm 1", 1 )
				)
			)}
		)
	)
);

Here is the restructured data table that was used to create the final chart.

txnelson_1-1695094803771.png

 

Jim
WoHNY
Level III

Re: Graph Builder Stacked Bar Chart

Jim:

Thank you for your response. I was unaware of the Multiple Series Stack option so that is a great tip. The only issue with the graph you generated was the Y-axis. I was looking for the Total % by Month as the overall height of the bar. So for Jan it would be 10%, Feb 4% & March 15%. The Y-axis would the monthly overall percent of fails. Then each of those bars would be subdivided into the percentages of the failing Parameters. The Jan 10% overall bar would be subdivided 20% Parm 1 / 80% Parm 2. The Feb 4% overall bar would be subdivided 16.7% Parm 1 / 50% Parm 2 / 33.3% Parm 3. Then the March 15% overall bar would be subdivided 37% Parm 1 / 29.6% Parm 2 / 33.3% Parm 3. I may need to adjust the table further because I cannot make it happen via Graph Builder as of yet. Thanks again.

txnelson
Super User

Re: Graph Builder Stacked Bar Chart

Changing to the % of Total is a simple math formula, give the columns in the stacked data table.  I just added a new column called % of Total, and then used it in the graph as the Y Axis

txnelson_0-1695142547483.png

Names Default To Here( 1 );
dt = Current Data Table();
dtStack = dt << Stack(
	columns(
		:Parm 1 # Fails, :Parm 2 # Fails, :Parm 3 # Fails, :Parm 1 % Fail,
		:Parm 2 % Fail, :Parm 3 % Fail
	),
	Source Label Column( "Parameter" ),
	Stacked Data Column( "Counts" ),
	Number of Series( 2 ),
	Contiguous
);

// Change the name of the column that has the % values
dtStack:Counts 2 << set name( "Percent" );

dtStack << New Column( "% of Total", Format( "Percent", 7, 0 ) );

// Divide each row value for the percent column to conform
// to the percent values for a JMP column
For Each Row(
	:Percent = :Percent / 100;
	:"% of Total"n = :counts / :Total Fails * (:total % Fail / 100);
);

// Change the display format for the percent column to 
// display a % sign in the values
dtStack:Percent << Format( "Percent", 7, 1 );

// A column needs to be set to have the correct display values for
// the legend.  Also, the alphabetical ordering will determine the
// order of the subbar values.  So recode the column to meet those
// specifications
// Recode column: Parameter
Local( {dt},
	dt = dtStack;
	dt << Begin Data Update;
	dt << Recode Column(
		dt:Parameter,
		{Map Value(
			_rcOrig,
			{"Parm 1 # Fails", "3. Parm 1", "Parm 2 # Fails", "2. Parm 2",
			"Parm 3 # Fails", "1. Parm 3"},
			Unmatched( _rcNow )
		)},
		Update Properties( 1 ),
		Target Column( :Parameter )
	);
	dt << End Data Update;
);

// Label column: Percent to be used to label the graph
dtStack:Percent << Label( 1 );
// Label all rows to show which values from the percent column
// to label
dtStack << Select All Rows << Label( 1 );
dtStack << clear selection;
dtStack << invert row selection;

// Draw the graph
Graph Builder(
	Size( 528, 450 ),
	Show Control Panel( 0 ),
	Variables( X( :Month ), Y( :"% of Total"n ), Overlay( :Parameter ) ),
	Elements(
		Bar( X, Y, Legend( 7 ), Bar Style( "Stacked" ), Label( "Label by Row" ) )
	),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				7,
				Properties( 0, {Fill Color( 73 )}, Item ID( "1. Parm 3", 1 ) ),
				Properties( 1, {Fill Color( 25 )}, Item ID( "2. Parm 2", 1 ) ),
				Properties(
					2,
					{Fill Color( -7183127 )},
					Item ID( "3. Parm 1", 1 )
				)
			)}
		)
	)
);
Jim
WoHNY
Level III

Re: Graph Builder Stacked Bar Chart

Jim:

I finally got something to work via Graph Builder. Thank you for the solution you provided. The Multiple Series you pointed out is a big help going forward as well as the code for this exercise. Thank you again.