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.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

Color on indicators

hcarr01
Level VI

Hello everyone,


I am trying to create a report in JMP to see drifts in certain processes.


For example, I study 6 items in my process and I would like to have an indicator with colors:

- if 5 consecutive points (or more) greater than 3sigma: red color

- if 3 consecutive points (or more) greater than 3sigma: yellow color

- otherwise green color


And then I would like to be able to display in a report something like this per item based on the indicator colors:

undefined


How could I go about having something similar on JMP?

Thank you for your reply.


This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User


Re: Couleur sur des indicateurs

My last script assumed you only wanted the last row in a series to retain the calculated color.  To accomplish what your latest specification, I just commented out the lines that reset the colors if the script determined it wasn't the last row in the series.

txnelson_0-1736771162139.png

names default to here(1);
dt = current data table();

// Créez une nouvelle colonne pour l'indicateur
dt << New Column("Indicateur", Character, Nominal);
	
one_color = "xyz";
icolor = 0;

For Each Row(
	// If the value of Article has changed set icolor to 0
	If( Lag( :Article ) != :Article,
		icolor = 0
	);
	// If status is red, increment icolor else set it back to zero
	If( :status == "red",
		icolor++,
		icolor = 0
	);
	// Check for the number of icolor
	// Set the value for the cell to the appropriate color
	// When a color is specified remove no longer correct cell colors
	// for previous rows
	If(
		icolor >= 5,
			dt:Indicateur << color cells("red",row());
			//dt:Indicateur << color cells("",row()-1);
			/*If( icolor == 5,
				dt:Indicateur << color cells("",row()-2);
			);*/,
		icolor >= 3,
			dt:Indicateur << color cells("yellow",row());
			//dt:Indicateur << color cells("",row()-1);
	);
);
Jim

View solution in original post

jthi
Super User


Re: Couleur sur des indicateurs

I'm not sure how this is anymore related to the initial question, but there is a bit different option for creating the indicator column

dt = Current Data Table();
dt << New Column("Color", Character, Nominal, 
	Set Property(
		"Value Colors",
		{"Green" = "Green", "Red" = "Red", "Yellow" = "Yellow"}
	),
	Color Cell By Value,
	Formula(
		is_red = :status == "red";
		
		If(Row() == 1,
			red_count = is_red;
		);
		
		If(:Article != Lag(:Article, 1) | is_red == 0,
			red_count = is_red;
		,
			red_count = red_count + is_red;
		);
		If(red_count >= 5,
			"Red";
		, red_count >= 3,
			"Yellow"
		,
			"Green"
		);
	)
);

 

-Jarmo

View solution in original post

12 REPLIES 12
txnelson
Super User


Re: Couleur sur des indicateurs

Is each "Item" in a separate column?

Are your data in sequential order"

How many different "Items" are there?

Should the report only have 3 different items in each row of the report?

Jim
hcarr01
Level VI


Re: Couleur sur des indicateurs

Is each "Item" in a separate column?  Yes one item by column

Are your data in sequential order"  Yes it can be sort in a sequential order

How many different "Items" are there?  A lot of....

Should the report only have 3 different items in each row of the report?  Yes

jthi
Super User


Re: Couleur sur des indicateurs

One simple option is something like this

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(6),
	Compress File When Saved(1),
	New Column("item",
		Character,
		"Nominal",
		Set Values({"ITEM1", "ITEM2", "ITEM3", "ITEM4", "ITEM5", "ITEM6"})
	),
	New Column("status",
		Character,
		"Nominal",
		Set Values({"Green", "Green", "Red", "Yellow", "Green", "Red"})
	)
);

lub = Lineup Box(N Col(3));

For Each Row(dt,
	Eval(EvalExpr(
		lub << Append(
			Text Box(:item, << Background Color(Expr(:status)))
		)		
	));
);

nw = New Window("",
	lub
);

jthi_0-1736410983729.png

 

-Jarmo
hcarr01
Level VI

Re: Color on indicators

Thanks for the reply, I'm trying to create a similar table with red, yellow and green indicators.


My goal is to create:

- if 5 consecutive points (or more) are red (above 3 sigma) so the color of the last point is red

- if 3 consecutive points (or more) are red (above 3 sigma) so the color of the last point is yellow

- otherwise green color


Attached you can find a table that serves as an example, I created the following script but without success:

dt = current data table();

// Créez une nouvelle colonne pour l'indicateur
dt << New Column("Indicateur", Character, Nominal);



// Boucle pour calculer l'indicateur ligne par ligne
For(i = 1, i <= N Rows(5), i++, 
    // Récupérer les 5 dernières valeurs de l'indicateur
    last_five = dt:status[i,5];  //
    
    // Comptez le nombre de "rouge"
    count_rouge = N Items( last_five == "rouge");
    
    // Attribuer une couleur en fonction des règles
    If(count_rouge == 5,
        dt:Indicateur Global[i] = "rouge"; // 5 rouges
    ,
        If(count_rouge >= 3,
            dt:Indicateur Global[i] = "jaune"; // 3 ou plus rouges
        ,
            dt:Indicateur Global[i] = "vert"; // Sinon vert
        );
    );
);

This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

txnelson
Super User


Re: Couleur sur des indicateurs

I remain confused.  However, given the data table you supplied, which appears to be a table that has the results of what you are attempting to calculate, one can easily color the cells for your Indicateur column

txnelson_0-1736426170368.png

names default to here(1);
dt=current data table();
dt << New Column("Indicateur", Character, Nominal);

:indicateur << color cells("red",dt<<get rows where(:status=="red"));
:indicateur << color cells("yellow",dt<<get rows where(:status=="yellow"));
:indicateur << color cells("green",dt<<get rows where(:status=="green"));

or can create a separate report

txnelson_1-1736426542617.png

nw=new window("colors", lub=lineupbox(ncol(3)));

For Each Row(dt,
	Eval(EvalExpr(
		lub << Append(
			Text Box("Item" || char(:item), << Background Color(Expr(:status)))
		)		
	));
);
Jim
jthi
Super User


Re: Couleur sur des indicateurs

If you want to have a table, use data table and color the cells. In graph builder you might be able to use heatmap. If you want to script it, you have many different options where you can set the background color.

-Jarmo
pmroz
Super User


Re: Couleur sur des indicateurs

I think this code does what you want:

dt = New Table( "testcolors", Add Rows( 15 ),
	New Column( "Article", Character, "Nominal",
		Set Values( {"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A"}
		) ),
	New Column( "Item", Numeric, "Continuous", Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] )
	),
	New Column( "status", Character, "Nominal",
		Set Values(
			{"red", "red", "red", "green", "green", "red", "red", "red", "red",
			"red", "red", "green", "red", "red", "red"}
		)
	),
// Créez une nouvelle colonne pour l'indicateur
	New Column("Indicateur", Character, Nominal)
);

one_color = "xyz";
icolor = 0;

for (i = 1, i <= nrows(dt), i++,
	one_color = dt:status[i];
	if (one_color == "red",
		icolor++;
	// else
	,
		if (icolor >= 5,
			dt:Indicateur << Color Cells( "Red", i-1 );
			icolor = 0;
		// else
			,
			icolor >= 3,
			dt:Indicateur << Color Cells( "Yellow", i-1 );
			icolor = 0;
		);
	);
);
// Handle the last row
if (icolor >= 5,
	dt:Indicateur << Color Cells( "Red", i-1 );
// else
	,
	icolor >= 3,
	dt:Indicateur << Color Cells( "Yellow", i-1 );
);

pmroz_0-1736426492609.png

 

hcarr01
Level VI

Re: Color on indicators

Hello, thanks for the reply, it works well on this test base!


I'm trying to generalize this script when I have multiple articles. The color indicators are created per article.

I am using the following script but I am not getting the correct end result:



dt = current data table();

// Créez une nouvelle colonne pour l'indicateur
dt << New Column("Indicateur", Character, Nominal)
	
	
one_color = "xyz";
icolor = 0;


Summarize(dt, unique_objects = by(:Article));
m_obs = dt[0, "Article"];

For each( {unique_objects}, m_obs,
for (i = 1, i <= nrows(dt), i++,
	one_color = dt:status[i];
	if (one_color == "red",
		icolor++;
	// else
	,
		if (icolor >= 5,
			dt:Indicateur << Color Cells( "Red", i-1 );
			icolor = 0;
		// else
			,
			icolor >= 3,
			dt:Indicateur << Color Cells( "Yellow", i-1 );
			icolor = 0;
		);
	);
);
// Handle the last row
if (icolor >= 5,
	dt:Indicateur << Color Cells( "Red", i-1 );
// else
	,
	icolor >= 3,
	dt:Indicateur << Color Cells( "Yellow", i-1 );
);
);

The result obtained:


undefined

Line 18 should have the yellow color because there are 3 consecutive red points for article B...


This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

txnelson
Super User


Re: Couleur sur des indicateurs

Here is my approach

txnelson_0-1736510845084.png

 
names default to here(1);
dt = current data table();

// Créez une nouvelle colonne pour l'indicateur
dt << New Column("Indicateur", Character, Nominal);
	
one_color = "xyz";
icolor = 0;

For Each Row(
	// If the value of Article has changed set icolor to 0
	If( Lag( :Article ) != :Article,
		icolor = 0
	);
	// If status is red, increment icolor else set it back to zero
	If( :status == "red",
		icolor++,
		icolor = 0
	);
	// Check for the number of icolor
	// Set the value for the cell to the appropriate color
	// When a color is specified remove no longer correct cell colors
	// for previous rows
	If(
		icolor >= 5,
			dt:Indicateur << color cells("red",row());
			dt:Indicateur << color cells("",row()-1);
			If( icolor == 5,
				dt:Indicateur << color cells("",row()-2);
			);,
		icolor >= 3,
			dt:Indicateur << color cells("yellow",row());
			dt:Indicateur << color cells("",row()-1);
	);
);
Jim