Binding Colors to Field Values in a Chart

How to:

Color binding enables you to associate (bind) BY field values to particular colors so that the same value will appear in the same color on different charts, regardless of the sequence or filter conditions. The BY field for which color binding is specified must be assigned to the color attribute category. For example, if the BY field is COUNTRY, that field should be assigned to the color attribute category. Then you can specify that the value France of the COUNTRY field should be red in every chart on every page of a report. The legend markers will also be bound to these colors.

Syntax: How to Bind a Color to a Field Value

type=data, marker-color=color, when=field eq value, $

where:

color

Specifies a color for the chart and legend marker when the condition in the WHEN phrase is satisfied. Color names, RGB color values, and hex color values are supported.

field

Is the name of the BY field that is assigned to the color attribute category whose values will be bound to specific colors.

value

Is the value that is bound to the color specified by the marker-color attribute.

Reference: Usage Notes for Color Binding

  • Color binding is supported when only one field is assigned to the color attribute category.
  • The only operator supported in the WHEN condition is EQ.
  • Color binding is only supported with chart attribute syntax.
  • The COLUMN attribute, which is generally required when applying conditional styling to charts, is optional for color binding, making it easier to reuse color mappings in separate procedures.
  • If there are BY values for which no color is explicitly specified, their colors are whatever series color is specified by the StyleSheet (or by chart engine defaults, if there is no StyleSheet).

Example: Binding Field Values to Colors in a Bar Chart

The following request binds the field values of the PRODUCT_CATEGORY field to specific colors.

GRAPH FILE WF_RETAIL_LITE
SUM COGS_US 
BY PRODUCT_CATEGORY
BY BUSINESS_REGION
WHERE BUSINESS_REGION NE 'Oceania'
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET LOOKGRAPH BAR
ON GRAPH SET STYLE *
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/ibi_themes/Warm.sty,$
TYPE=DATA, COLUMN=BUSINESS_REGION, BUCKET=X-AXIS, $
TYPE=DATA, COLUMN=COGS_US, BUCKET=y-axis, $
TYPE=DATA, COLUMN=PRODUCT_CATEGORY, BUCKET=COLOR, $
TYPE=DATA, MARKER-COLOR=red, WHEN=PRODUCT_CATEGORY EQ 'Accessories',$
TYPE=DATA, MARKER-COLOR=orange, WHEN=PRODUCT_CATEGORY EQ 'Camcorder',$
TYPE=DATA, MARKER-COLOR=yellow, WHEN=PRODUCT_CATEGORY EQ 'Computers',$
TYPE=DATA, MARKER-COLOR=green, WHEN=PRODUCT_CATEGORY EQ 'Media Player',$
TYPE=DATA, MARKER-COLOR=blue, WHEN=PRODUCT_CATEGORY EQ 'Stereo Systems',$
TYPE=DATA, MARKER-COLOR=purple, WHEN=PRODUCT_CATEGORY EQ 'Televisions',$
TYPE=DATA, MARKER-COLOR=gray, WHEN=PRODUCT_CATEGORY EQ 'Video Production',$
ENDSTYLE
END

The following version of the request binds the field values of the PRODUCT_CATEGORY field to the same colors, but filters out the product categories that start with the letter C.

GRAPH FILE WF_RETAIL_LITE
SUM COGS_US 
BY PRODUCT_CATEGORY
BY BUSINESS_REGION
WHERE PRODUCT_CATEGORY NOT LIKE 'C%'
WHERE BUSINESS_REGION NE 'Oceania'
ON GRAPH PCHOLD FORMAT JSCHART
ON GRAPH SET LOOKGRAPH BAR
ON GRAPH SET STYLE *
INCLUDE=IBFS:/FILE/IBI_HTML_DIR/ibi_themes/Warm.sty,$
TYPE=DATA, COLUMN=BUSINESS_REGION, BUCKET=X-AXIS, $
TYPE=DATA, COLUMN=COGS_US, BUCKET=y-axis, $
TYPE=DATA, COLUMN=PRODUCT_CATEGORY, BUCKET=COLOR, $
TYPE=DATA, MARKER-COLOR=red, WHEN=PRODUCT_CATEGORY EQ 'Accessories',$
TYPE=DATA, MARKER-COLOR=orange, WHEN=PRODUCT_CATEGORY EQ 'Camcorder',$
TYPE=DATA, MARKER-COLOR=yellow, WHEN=PRODUCT_CATEGORY EQ 'Computers',$
TYPE=DATA, MARKER-COLOR=green, WHEN=PRODUCT_CATEGORY EQ 'Media Player',$
TYPE=DATA, MARKER-COLOR=blue, WHEN=PRODUCT_CATEGORY EQ 'Stereo Systems',$
TYPE=DATA, MARKER-COLOR=purple, WHEN=PRODUCT_CATEGORY EQ 'Televisions',$
TYPE=DATA, MARKER-COLOR=gray, WHEN=PRODUCT_CATEGORY EQ 'Video Production',$
ENDSTYLE
END

Both charts are shown in the following image. Note that, although Media Player is represented by the fourth riser on chart 1 and the second riser on chart 2, it is green on both charts.

WebFOCUS

Feedback