BookmarkSubscribe
Choose Language Hide Translation Bar
TWE
TWE
Contributor

Constant legend color

Hi,

 

I build a graph (bar chart) and changed the legend color (and therfore the bar color) by right-clicking and copy the script

SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				8,
				Properties( 0, {Fill Color( 10 )}, Item ID( "category", 1 ) ),

This is part of a bigger graph.

 

When I run the script and include a local data filter, the color for the categories are changing. This is detrimental because I want to have the same color for a category independently of a filter.

 

Kind regards,

 

 

0 Kudos
3 ACCEPTED SOLUTIONS

Accepted Solutions
stephen_pearson
Community Trekker

Re: Constant legend color

You can lock the legend colours by using the column property - Value Colors. This will ensure whatever platform you are and what ever local data filter is applied the colours for each group will not change.
txnelson
Super User

Re: Constant legend color

You should be able to unclick the "Include" checkbox in the filter, to allow the chart's colors to stay the same. The "Include" checkbox tells the filter to Include/Exclude values in calculating the chart, so when it is not checked, it uses all of the values, thus the colors are calculated the save from filtered value to filtered value.
Jim
txnelson
Super User

Re: Constant legend color

You can not change the Fill Color by changing the Cell Color nor by changing the Row State of Color to a specified color.  A bar chart is a calculated column, that does not have a direct relationship from the display and each individual row.  Therefore, you need to deal with the whole bar by changing the Fill Color within the Graph Builder Code.  Below is an example on how to do this:

Graph Builder(
	Size( 534, 418 ),
	Show Control Panel( 0 ),
	Variables( Y( :height ), Y( :weight, Position( 1 ) ) ),
	Elements( Bar( Y( 1 ), Y( 2 ), Legend( 3 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				3,
				Properties( 0, {Fill Color( 5 )}, Item ID( "Mean(height)", 1 ) ),
				Properties( 1, {Fill Color( 5 )}, Item ID( "Mean(weight)", 1 ) )
			)}
		)
	)
);

 

Jim
0 Kudos
5 REPLIES 5
stephen_pearson
Community Trekker

Re: Constant legend color

You can lock the legend colours by using the column property - Value Colors. This will ensure whatever platform you are and what ever local data filter is applied the colours for each group will not change.
Highlighted
TWE
TWE
Contributor

Re: Constant legend color

Thanks,

I'm afraid that the answer of the next question is obviously, but how can I change all values in a column to a single color, via script?

0 Kudos
TWE
TWE
Contributor

Re: Constant legend color

I colored all cells in two columns (heigt and weight) to get the same color in a bar chart but it didnt work

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

:height << Color Cell By Value( 1 ); // turn on the cell coloring
For( i = 1, i <= N Row( dt ), i++,

	If( Column( dt, "height" )[i] >= 0,

		Column( dt, "height" ) << Color Cells( 5, {i} ),

		Column( dt, "height" ) << Color Cells( 0, {i} )

	));
:weight << Color Cell By Value( 1 ); // turn on the cell coloring
For( i = 1, i <= N Row( dt ), i++,
	If( Column( dt, "weight" )[i] >= 0,

		Column( dt, "weight" ) << Color Cells( 5, {i} ),

		Column( dt, "weight" ) << Color Cells( 0, {i} )

	));

Graph Builder(
	Size( 534, 418 ),
	Show Control Panel( 0 ),
	Variables( Y( :height ), Y( :weight, Position( 1 ) ) ),
	Elements( Bar( Y( 1 ), Y( 2 ), Legend( 3 ) ) )
);
0 Kudos
txnelson
Super User

Re: Constant legend color

You can not change the Fill Color by changing the Cell Color nor by changing the Row State of Color to a specified color.  A bar chart is a calculated column, that does not have a direct relationship from the display and each individual row.  Therefore, you need to deal with the whole bar by changing the Fill Color within the Graph Builder Code.  Below is an example on how to do this:

Graph Builder(
	Size( 534, 418 ),
	Show Control Panel( 0 ),
	Variables( Y( :height ), Y( :weight, Position( 1 ) ) ),
	Elements( Bar( Y( 1 ), Y( 2 ), Legend( 3 ) ) ),
	SendToReport(
		Dispatch(
			{},
			"400",
			ScaleBox,
			{Legend Model(
				3,
				Properties( 0, {Fill Color( 5 )}, Item ID( "Mean(height)", 1 ) ),
				Properties( 1, {Fill Color( 5 )}, Item ID( "Mean(weight)", 1 ) )
			)}
		)
	)
);

 

Jim
0 Kudos
txnelson
Super User

Re: Constant legend color

You should be able to unclick the "Include" checkbox in the filter, to allow the chart's colors to stay the same. The "Include" checkbox tells the filter to Include/Exclude values in calculating the chart, so when it is not checked, it uses all of the values, thus the colors are calculated the save from filtered value to filtered value.
Jim