Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using a Color Variable in a Histogram Control

The default color is yellow for all of the bars in a histogram. To make color a response variable in the graph, you can specify a numeric variable whose values are indexed into the defined color range to determine the colors to use in the graph.

To assign the color variable, use the colorVariable attribute. The colors can represent the Sum, Mean, or Frequency statistic for the dependent variables. To specify the statistic represented by the color variable, use the colorVariableStatistic attribute.

For a Histogram control named histogram1, the following code sets the colorVariable to Sales and the colorVariableStatistic to Sum:

histogram1.colorVariable = 'sales';
histogram1.colorVariableStatistic = 'sum';

The color is applied in a color range from yellow to red, with yellow representing the lowest values of the color variable and red representing the highest:

[IMAGE]

To change the default color values that represent a color variable's values, you can define an alternative color range in either of two ways:


Creating a Color List in a Histogram Control

To supply your own color list of up to 64 colors:

In build mode, you can define a color list by selecting the colorList attribute, and then selecting the button that appears in the Value column. This opens the List Editor so that you can define the list of colors.

To define a color list in SCL code, make an SCL list, populate it with the list of color values, and then assign the list to the control's colorList attribute. Your code might resemble the following for a control named histogram1:

/* Make the list */
clist = makelist(3);
rc = setitemc(clist,'Red',1);
rc = setitemc(clist,'Yellow',2);
rc = setitemc(clist,'Green',3);

/* varName is the color variable's name */
histogram1.colorVariable='varName';
histogram1.colorList=clist;

The colors in your specified list are distributed evenly across the range of values in the color variable. Thus, if you define three colors in the list, only three bar colors are used. The first color in the list represents the lowest third of the color variable's values, the second color in the list represents the middle third of the color variable's values, and the third color represents the highest third.

You can also create a list of blended colors. The following code creates a color series that ranges from red to blue:

rcolor= ' ';
gcolor = ' ';
bcolor = ' ';
r = 255;
g = 0;
b = 0;
fmt = 'hex2.';
clist = makelist(16);
do i = 1 to 16;
  rcolor = putn(r,fmt);
  gcolor = putn(g, fmt);
  bcolor = putn(b, fmt);
  cval = 'CX' || rcolor || gcolor || bcolor;
  retc = setitemc(clist,cval,i);
  r = r - 14;
  b = b + 14;
end;

/* varName is the color variable's name */
histogram1.colorVariable='varName';
histogram1.colorList=clist;

The colors in the list are distributed evenly across the range of values in the color variable:

[IMAGE]

To return to using the default colors, assign an empty list to the colorList attribute:

clist = makelist();
/* varName is the color variable's name */
histogram1.colorVariable='varName';
histogram1.colorList=clist;


Using a Range Entry in a Histogram Control

You can use a Range entry as the color source for a Histogram control. A Range entry is a catalog entry of type RANGE. The entry defines a range having up to 24 segments, each of which is assigned a numeric range, a color, and an attribute. For example, segment 1 might be assigned the numeric range from 0 to 5, the color Blue, and the attibute Blinking; segment 2 might be assigned the numeric range from 6 to 10, the color Green, and the attribute Highlight; and so on. A Histogram control supports the numeric ranges and the colors assigned to the segments, but it does not support the attributes (Blinking, Highlight, Reverse, Underline, and Hirev).

When used with a Histogram control, the numeric ranges that are defined in the Range entry's segments are indexed into the values of the color variable that is assigned to the Histogram control. So, using the segments defined above, the values from 0 to 5 in the color variable will be represented by Blue in the graph, and the values from 6 to 10 will be represented by Green, and so on.

To use a Range entry, you must do all of the following:

To create a Range entry, use the Range Entry window, which you can open from the SAS command line. If you need help defining the segments, use the window's Help button to get help. The following command opens the Range Entry window to create a temporary Range entry in the WORK library:

build work.color.myrange.range

After creating the Range entry, you can use its color definitions as the color source in a Histogram control. For example, if you used the command above to create a Range entry, the following code applies that entry's colors to a Histogram control named histogram1:

/* varName is the color variable's name */
histogram1.colorVariable='varName';
histogram1.colorSource='ColorRangeObject';
histogram1.colorRangeObject='work.color.myrange.range';


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.