version 6.0 (Modified)
Version 6 Note: Starting with version 6, graphs are now supported by the 4D Chart Plug-in, which is integrated within 4th Dimension. The Graph commands from the previous version of 4D are transparently redirected to 4D Chart. In addition, to use the additional 4D Chart commands for customizing a Graph Area located in a form, use the graphArea parameter (described in this command) as an external area reference for the 4D Chart commands. For detailed information about the 4D Chart commands, refer to the 4D Chart Reference manual.
The GRAPH command is designed to be used with a graph area created in a 4D form. It must be used in a form method or in an object method of one of the form's objects. It can also be used in a method called by one of these methods.
GRAPH (graphArea; graphNumber; xLabels; yElements{; yElements2; ...; yElementsN})
Parameter | Type | Description | |
graphArea | Variable | Graph area in the form | |
graphNumber | Number | Graph type number | |
xLabels | Array or Subfields | Labels for the x-axis | |
yElements | Array or Subfields | Data to graph (up to eight allowed) |
Description
GRAPH draws a graph for a Graph area located in a form. The data can come from either arrays or subfields.
The graphArea parameter is the name of the Graph area that displays the graph. The Graph area is created in the Form editor, using the graph object type. The graph name is the name entered for the variable name. For information about creating a Graph area, see the 4th Dimension Design Reference.
The graphNum parameter defines the type of graph that will be drawn. It must be a number from 1 to 8. The graph types are described in Example 1. After a graph has been drawn, you can change the type by changing graphNum and executing the GRAPH command again.
The xLabels parameter defines the labels that will be used to label the x-axis (the bottom of the graph). This data can be of string, date, time, or numeric type. There should be the same number of subrecords or array elements in xLabels as there are subrecords or array elements in each of the yElements.
The data specified by yElements is the data to graph. The data must be numeric. Up to eight data sets can be graphed. Pie charts graph only the first yElements.
Examples
1. The following example shows how to use arrays to create a graph. The code would be inserted in a form method or object method. It is not intended to be realistic, since the data is constant:
ARRAY STRING (4; X; 2) ` Create an array for the x-axis X{1}:="1995" ` X Label #1 X{2}:="1996" ` X Label #2 ARRAY REAL (A; 2) ` Create an array for the y-axis A{1}:=30 ` Insert some data A{2}:=40 ARRAY REAL (B; 2) ` Create an array for the y-axis B{1}:=50 ` Insert some data B{2}:=80 GRAPH (vGraph;vType; X; A; B) ` Draw the graph GRAPH SETTINGS (vGraph;0;0;0;0;False;False;True;"France";"USA") ` Set the legends for the graph
The following figure shows the resulting graph.
With vType equal to 1, you obtain a Column graph:
With vType equal to 2, you obtain a Proportional Column graph:
With vType equal to 3, you obtain a Stacked Column graph:
With vType equal to 4, you obtain a Line graph:
With vType equal to 5, you obtain a Area graph:
With vType equal to 6, you obtain a Scatter graph:
With vType equal to 7, you obtain a Pie graph:
With vType equal to 8, you obtain a Picture graph:
2. The following example graphs the sales in dollars for sales people in a subtable. The subtable has three fields: Name, LastYearTot, and ThisYearTot. The graph will show the sales for each of the sales people for the last two years:
GRAPH (vGraph;1;[Employees]Sales'Name;[Employees]Sales'LastYearTot;[Employees]Sales'ThisYearTot)
See Also
CT Chart arrays, CT Chart data, CT Chart selection, GRAPH SETTINGS, GRAPH TABLE.