BAR: Producing a Bar Chart

How to:

Available Languages: reporting, Maintain

The BAR function produces a horizontal bar chart using repeating characters to form each bar. Optionally, you can create a scale to clarify the meaning of a bar chart by replacing the title of the column containing the bar with a scale.

Syntax: How to Produce a Bar Chart

BAR(barlength, infield, maxvalue, 'char', output)

where:

barlength

Numeric

Is the maximum length of the bar, in characters. If this value is less than or equal to 0, the function does not return a bar.

infield

Numeric

Is the data field plotted as a bar chart.

maxvalue

Numeric

Is the maximum value of a bar. This value must be greater than the maximum value stored in infield. If infield is larger than maxvalue, the function uses maxvalue and returns a bar of maximum length.

'char'

Alphanumeric

Is the repeating character that creates the bars enclosed in single quotation marks. If you specify more than one character, only the first character is used.

output

Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. The output field must be large enough to contain a bar of maximum length as defined by barlength.

Example: Producing a Bar Chart

BAR creates a bar chart for the CURR_SAL field, and stores the output in SAL_BAR. The bar created can be no longer than 30 characters long, and the value it represents can be no greater than 30,000.

TABLE FILE EMPLOYEE
PRINT CURR_SAL AND COMPUTE
SAL_BAR/A30 = BAR(30, CURR_SAL, 30000, '=', SAL_BAR);BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'PRODUCTION';
END

The output is:

LAST_NAME       FIRST_NAME         CURR_SAL  SAL_BAR 
---------       ----------         --------  -------
BANNING         JOHN             $29,700.00  =========================== 
IRVING          JOAN             $26,862.00  ========================== 
MCKNIGHT        ROGER            $16,100.00  ================ 
ROMANS          ANTHONY          $21,120.00  ===================== 
SMITH           RICHARD           $9,500.00  ========== 
STEVENS         ALFRED           $11,000.00  ===========

Example: Creating a Bar Chart With a Scale

BAR creates a bar chart for the CURR_SAL field. The request then replaces the field name SAL_BAR with a scale using the AS phrase.

To run this request on a platform for which the default font is proportional, use a non-proportional font or issue SET STYLE=OFF.

SET STYLE=OFF
TABLE FILE EMPLOYEE
HEADING
"CURRENT SALARIES OF EMPLOYEES IN PRODUCTION DEPARTMENT"
"GRAPHED IN THOUSANDS OF DOLLARS"
" "
PRINT CURR_SAL AS 'CURRENT SALARY'
AND COMPUTE
    SAL_BAR/A30 = BAR(30, CURR_SAL, 30000, '=', SAL_BAR);
    AS '    5   10   15   20   25   30,----+----+----+----+----+----+'
BY LAST_NAME AS 'LAST NAME'
BY FIRST_NAME AS 'FIRST NAME'
WHERE DEPARTMENT EQ 'PRODUCTION';
ON TABLE SET PAGE-NUM OFF
ON TABLE SET STYLE * GRID=OFF, $
END

The output is:

CURRENT SALARIES OF EMPLOYEES IN PRODUCTION DEPARTMENT 
GRAPHED IN THOUSANDS OF DOLLARS
                                               5 10 15 20 25 30 
LAST NAME    FIRST NAME    CURRENT SALARY ----+----+----+----+----+----+ 
---------    ----------    -------------- ------------------------------ 
BANNING      JOHN          $29,700.00     ============================= 
IRVING       JOAN          $26,862.00     =========================== 
MCKNIGHT     ROGER         $16,100.00     ================ 
ROMANS       ANTHONY       $21,120.00     ===================== 
SMITH        RICHARD        $9,500.00     ========== 
STEVENS      ALFRED        $11,000.00     ===========