Converting the Graph Commands to 4D Chart


ACI - Documentation Français English German ACI Technical Notes ACI Technical Notes, By Subject Back Previous Next

Converting the Graph Commands to 4D Chart

By Tim Tonooka, ACI Technical Support

Technical Note 98-27

Technical Notes for Technical Notes for 98-09-September 1998

Introduction


Technical note 98-22, "The GRAPH Command in 4D V6," discussed the differences between the Graph commands of 4D V3 and V6. The Graph commands are still supported in 4D V6, so that your previous code can still be used, but now 4D Chart acts as the engine behind the scenes that actually performs all graphing operations. If the capabilities of the Graph commands suit your needs, it is fine to continue using them.

But now that 4D Chart is built into 4th Dimension, you may be interested in building graphs with 4D Chart, instead of the GRAPH, GRAPH TABLE, and GRAPH SETTINGS commands. This technical note covers the details of implementing the features of the Graph commands in 4D Chart, focusing on creating graphs from arrays. A variety of tips and tricks are included, and two example databases are provided.

In this technical note, all references to 4D V3 refer to all versions of 4D 3.x.x and 4D Server 1.x.x.

When should you build graphs with 4D Chart commands, instead of the Graph commands?


You can create more attractive graphs in 4D Chart. Its 118 commands give you a tremendous amount of control over your graphs.

In 4D V6, you can also use the 4D Chart commands to further control the appearance of graphs created with the Graph commands. This technique was detailed in technical note 98-22. If you are using more than just a few 4D Chart commands this way, your code will be clearer if you implement the graph entirely in 4D Chart.

Since 4D Chart is the internal engine that draws all graphs in 4D V6, if you implement your graphs entirely in 4D Chart, your code will be written in line with a closer understanding of how the graphing is actually handled by 4D.

When you create a graph in a 4D Chart area, many additional features can be made available to the user via the 4D Chart menu bar and tool bar. These additional capabilities are not available to the user with graphs created by the Graph commands.

Even if you don't need the full capabilities of 4D Chart now, if you create your graphs in 4D Chart, it will be easier for you to enhance these graphs with additional 4D Chart features later.

Converting the syntax of the Graph commands to 4D Chart


Behind the scenes, when you use the GRAPH or GRAPH TABLE commands in 4D V6, not only do they internally use 4D Chart to create graphs, they also perform the equivalent of additional 4D Chart commands, to maintain features of graphs created with the Graph commands of 4D V3. For example, if you use the 4D V6 GRAPH command to create a pie chart, it instructs 4D Chart to add labels to the pie wedges. If you build a pie chart directly in 4D Chart, you'll need to use a separate 4D Chart command to add those labels.

Once you gain familiarity with the basics of using the 4D Chart commands, you'll be able to refine the styling of your graphs to a much greater level of detail than is possible with the Graph commands alone.

A basic overview of the 4D Chart commands


One way to categorize 4D Chart's 118 commands is by their scope. Some of the commands act on the entire 4D Chart area. There is another group of commands to create individual objects within a 4D Chart area. These objects can include text, lines, rectangles, ovals, and polygons. Pictures can also be placed in a 4D Chart area. Most commonly, you create graphs, using the CT Chart arrays, CT Chart selection, and CT Chart data commands. 4D Chart has many commands that you can then use to control the appearance of graphs to a fine level of detail. The scope of these commands ranges from the entire graph to individual components of the graph. The remaining 4D Chart commands provide links to other plug-ins, handle printing, and provide other functions helpful in creating graphs.

To facilitate the writing of code with the 4D Chart commands, a series of unique ID codes identify the various objects in a 4D Chart area. Starting at the largest level, there are Area ID codes for individual 4D Chart areas. Within a 4D Chart area, Object ID codes identify individual objects, including graphs. Within one 4D Chart area, you can have multiple graph objects — it is not necessary to create a separate 4D Chart area for each graph on a form. Within a graph object, nine partType codes identify the basic sections of a graph: Plot rectangle, Legend, Axis, Label, Title, Major grid lines, Minor grid lines, Series, or Value labels for series. Within a section identified by a partType code, there are partSpecifics codes to specify an even finer level of detail. For example, partType code 3 covers all the axes of a graph, and within that, partSpecifics codes are used to specify individual axes. Understanding these partType and partSpecifics codes is essential for using the 4D Chart commands to control the appearance of graphs.

Comparing the GRAPH command, and the CT Chart arrays command


Let's examine the correlation between the parameters used by the GRAPH command and 4D Chart to create graphs from arrays.

To create a graph from arrays with the GRAPH command, at least four parameters are needed:

GRAPH (graphArea; graphNumber; xLabels; yElements{; yElements2; ...; yElementsN})

To create a graph from arrays with 4D Chart, the CT Chart arrays command is used. It requires six parameters:

CT Chart arrays (area; type; size; categoryArray; seriesArray; valuesArray) ' Number

The graphArea parameter of the GRAPH command serves the same function as the area parameter of the CT Chart arrays command: specifying where on the form the graph will be displayed. For the GRAPH command, you specify a graph variable, and for the CT Chart arrays command, you specify the 4D Chart area.

The graphNumber parameter of the GRAPH command serves the same function as the type parameter of the CT Chart arrays command. The two commands use different codes. Every graph you can create with the GRAPH command can be created in 4D Chart:

GRAPH4D Chart
Graph typenumber number

Column12
Proportional column22 (combine with CT SET CHART OPTIONS command)
Stacked column32 (combine with CT SET CHART OPTIONS command)
Line44
Area51
Scatter65
Pie76
Picture83

The GRAPH command's graphNumber parameter allows eight different types of graphs. 4D Chart's type parameter can specify fourteen different graphs. By using 4D Chart's graph types together with the CT SET CHART OPTIONS command, you can create even more varieties of graphs. Most of 4D Chart's 2-D graphs can be displayed in either a horizontal or vertical orientation, and can also be shown in a stacked, or stacked proportional view.

The CT Chart arrays, CT Chart selection, and CT Chart data commands of 4D Chart have a size parameter. If you use the resizeable forms feature of 4D V6, it is best to use the value 2 for this parameter, so your graph will automatically resize itself within a 4D Chart area, as the area resizes itself together with the form. This is demonstrated in the "V6GraphToChart" example database.

Differences between the arrays used to create graphs with the Graph commands and 4D Chart

When creating a graph from arrays in 4D Chart, you need three different arrays, known in the 4D Chart terminology as the Categories array, the Series array, and the Values array.

The Categories array identifies the divisions along the x-axis of the graph. It is the same as the xLabels array used as the third parameter of the GRAPH command.

The Series array holds the names of each curve plotted on the graph. The elements of this array hold the same data used in the individual title parameters of the GRAPH SETTINGS command.

The Values array holds the values of all the points plotted on the graph. A major difference between 4D Chart and the GRAPH command is that with the GRAPH command, there is a separate array for each graphed curve, to hold the values for the points along that curve. These are the yElements arrays that start at the fourth parameter of the GRAPH command. In 4D Chart, these separate arrays of graph curve values are all combined into one array.

For example, to create a Line graph with the GRAPH command, if you had two graph curves, with three points of data on each curve, you would specify two separate arrays, each with three elements, in the yElements parameters of the GRAPH command:

yElements1{1} ` curve 1, point 1

yElements1{2} ` curve 1, point 2

yElements1{3} ` curve 1, point 3

yElements2{1} ` curve 2, point 1

yElements2{2} ` curve 2, point 2

yElements2{3} ` curve 2, point 3

In 4D Chart, you would combine these two arrays together into one Values array. The values for the points along the first curve go into the first three elements of this combined Values array, and the values for the points along the second curve go into the next three elements in the combined Values array. The elements of the combined array are in this order:

valuesArray{1} ` curve 1, point 1

valuesArray{2} ` curve 1, point 2

valuesArray{3} ` curve 1, point 3

valuesArray{4} ` curve 2, point 1

valuesArray{5} ` curve 2, point 2

valuesArray{6} ` curve 2, point 3

The exceptions to this description of the arrays are the pie chart, 2D XY, and Polar graphs.

For every graph type, in order for 4D Chart to display a graph created from arrays, the number of elements in the Values array must be equal to the number of elements in the Categories array multiplied by the number of elements in the Series array. If this rule is not followed, 4D Chart will not draw the graph.

Creating the arrays for a pie chart

The number of pie wedges that will be displayed is equal to the number of elements in the Categories array. There must be at least that many elements in the Values array. Even though the Series array is not used in the display of a pie chart, you must still have a Series array, and the number of elements in it must be equal to the number of elements in the Values array divided by the number of elements in the Categories array.

Unless you use the CT SET LEGEND TEXT command to specify otherwise, the titles in the legend come from the Categories array.

Creating the arrays for a 2D XY graph

In a 2D XY graph, the x and y coordinates of each point on the graph are specified separately, so two elements in the Values array are required for each point to be plotted on the graph. The sequence of the elements in the Values array is: all x coordinates for the first graph curve, followed by all y coordinates for the first graph curve. This sequence then repeats for the remaining curves.

To implement the previous example of two graph curves, each with three points of data, in a 2D XY graph, you need to configure the elements of the Values array in this order:

valuesArray{1} ` curve 1, point 1: x coordinate

valuesArray{2} ` curve 1, point 2: x coordinate

valuesArray{3} ` curve 1, point 3: x coordinate

valuesArray{4} ` curve 1, point 1: y coordinate

valuesArray{5} ` curve 1, point 2: y coordinate

valuesArray{6} ` curve 1, point 3: y coordinate

valuesArray{7} ` curve 2, point 1: x coordinate

valuesArray{8} ` curve 2, point 2: x coordinate

valuesArray{9} ` curve 2, point 3: x coordinate

valuesArray{10} ` curve 2, point 1: y coordinate

valuesArray{11} ` curve 2, point 2: y coordinate

valuesArray{12} ` curve 2, point 3: y coordinate

In a 2D XY graph, you are required to have two elements in the Series array for each curve you wish to graph. The sequence of the elements in the Series array is: the name of the x coordinates for the first curve, followed by the name of the y coordinates for the first curve. This sequence then repeats for the remaining curves. By default, the graph legend combines pairs of these names into titles for the graph curves. For example, if the first two elements of the Series array were "Series 1" and "Series 2," the legend would show the first curve's title as "Series 1-Series 2." You can use the CT SET LEGEND TEXT command to specify your own titles for the graph legend.

The data in the Categories array is not used in a 2D XY graph, but you are still required to have a Categories array, and the number of elements in it must be equal to the number of elements in the Values array divided by the number of elements in the Series array.

Because a 2D XY graph allows you to control the absolute position of each point on the graph, you can do things that would be impossible in a normal graph. Since you control not only the vertical position of each point, but also its sideways position along the x-axis, your graph curves could flow in any direction you please. The curves do not have to march in even steps from one side of the x-axis to the other. They could reverse direction, or even form the shape of a spiral.

A practical use for this capability includes the scenario where you want to create a basic Line graph with several curves, but at some of the steps along the x-axis, you do not have values for every curve on the graph. In a normal graph, this commonly results in the graph curve dropping to zero at these points. Since these points represent missing data, it would be preferable if the line on the graph could just go straight from the previous point to the next one, rather than dipping to zero in between.

This effect can be created in a 2D XY graph. Though you still need to have an identical number of points on each curve, in your code you can manipulate the conversion of your data into arrays so that if data is missing for a point along the x-axis, both the x and y coordinates of that point remain the same as the point before it. The result is that the point for this missing data sits exactly on top of the last valid point, appearing to the viewer as if it was not there. This is demonstrated in the sample 2D XY graph in the "V6GraphToChart" example database:

Creating the arrays for a Polar graph

For each point plotted on a Polar graph, its distance from the center of the graph, and its rotation angle around the circular graph are specified separately. This requires two elements in the Values array for each point plotted on the graph. The sequence of elements in the Values array begins with the coordinates for the first curve on the graph: there is the set of coordinates for the distance of the points from the graph's center, followed by the set of coordinates for the angle of the points in degrees around the graph circle. This sequence repeats for the remaining graph curves.

To implement the previous example of two graph curves, each with three points of data, in a 2D Polar graph, you need to configure the elements of the Values array in this order:

valuesArray{1} ` curve 1, point 1: distance from center

valuesArray{2} ` curve 1, point 2: distance from center

valuesArray{3} ` curve 1, point 3: distance from center

valuesArray{4} ` curve 1, point 1: angle around circle

valuesArray{5} ` curve 1, point 2: angle around circle

valuesArray{6} ` curve 1, point 3: angle around circle

valuesArray{7} ` curve 2, point 1: distance from center

valuesArray{8} ` curve 2, point 2: distance from center

valuesArray{9} ` curve 2, point 3: distance from center

valuesArray{10} ` curve 2, point 1: angle around circle

valuesArray{11} ` curve 2, point 2: angle around circle

valuesArray{12} ` curve 2, point 3: angle around circle

To create a Polar graph, the Categories and Series arrays are configured the same as for a 2D XY graph. The titling for the legend also works the same way as a 2D XY graph.

Implementing the GRAPH SETTINGS command in 4D Chart


The GRAPH SETTINGS command allows you to customize a graph by specifying nine parameters. Here's how to implement their equivalents in 4D Chart.

graph

In the first parameter, you specify a graph area to which the other parameters of the GRAPH SETTINGS command will apply. In 4D Chart commands, you use an Area ID instead: the name of a 4D Chart area.

xmin and xmax

In the second and third parameters of the GRAPH SETTINGS command, you specify the minimum and maximum values for the x-axis of your graph. In 4D Chart, this is done with either the CT SET X REAL SCALE or CT SET X DATE SCALE commands, depending on whether the values on your scale are numbers or dates. You can only specify your own values for the x-axis if you are using a 2D XY graph, or if you are using the proportional x-axis feature on either a Line or Scatter graph (because that causes 4D Chart to internally implement these two graph types as a 2D XY graph).

ymin and ymax

In the fourth and fifth parameters of the GRAPH SETTINGS command, you specify the minimum and maximum values for the y-axis of your graph. In 4D Chart, this is done with either the CT SET REAL SCALE or CT SET DATE SCALE commands, depending on whether the values on your scale are numbers or dates.

xprop

This sixth parameter of the GRAPH SETTINGS command allows you to enable the proportional x-axis option. Normally, the values across the x-axis of your graph are spaced apart by the same amount, regardless of the relative difference between adjacent values. With the proportional x-axis feature enabled, the values along this Categories axis can be located along the axis in the position of their relative quantity, indicating where they would fall on a ruler or a time line. This feature can only be applied to a 2D Line graph or Scatter graph.

If you have constructed a graph in 4D Chart and want to access the proportional x-axis feature, you need to use the GRAPH SETTINGS command. Use the name of your 4D Chart area as the first parameter. Set the sixth parameter to True to turn on the proportional x-axis feature. Internally, this causes 4D Chart to recast your graph as a 2D XY graph. It is more complex to rework a Line or Scatter graph in the 2D XY graph format yourself. If you do so, you cannot mix data types together, such as by having numbers on the vertical axis and dates along the horizontal axis. However, you can accomplish this by using either a Line or Scatter graph with the proportional x-axis feature enabled. Normally you would not use the GRAPH SETTINGS command to act on a 4D Chart area, but this is one exception.

When using the GRAPH SETTINGS command to enable the proportional x-axis for a 4D Chart area, you will need to specify the desired range of your x-axis scale in both the GRAPH SETTINGS command and either the CT SET X REAL SCALE or CT SET X DATE SCALE commands of 4D Chart. Setting the scale range in the GRAPH SETTINGS command alone will usually not be sufficient.

Because a Line or Scatter graph is internally implemented by 4D Chart as a 2D XY graph when the proportional x-axis feature is enabled, if you use the CT SET CHART OPTIONS command on that graph, your available options will be those of a 2D XY graph, not a Line graph. These options allow you to hide the curve points, or display them as circles, squares, or stars. You can choose to hide the lines between points, or display them as straight lines or arrows. You can also choose to display regression lines.

Here is a sample Line graph created in 4D Chart, with the proportional x-axis feature enabled. Notice that the years are proportionally spaced apart on the time line, leaving a gap between points for the missing 1996 data.

xgrid and ygrid

The xgrid parameter of the GRAPH SETTINGS command lets you display or hide the vertical grid lines that are spaced apart along the x-axis of the graph. The ygrid parameter lets you display or hide the horizontal grid lines spaced apart along the y-axis. In 4D Chart, you can use the CT SHOW GRID LINES command to display or hide the grid lines along any axis.

title

The remaining title parameters of the GRAPH SETTINGS command allow you to set the titles for the graph legend. In 4D Chart, the titles in the graph legend will by default come from the Series array. (The exception is a pie chart, which takes the default titles from the Categories array.) To override the default titles, you can use the CT SET LEGEND TEXT command.

Converting a Line graph to 4D Chart


To demonstrate the process of creating a graph in 4D Chart, as compared to using the GRAPH command, we will work through an example of a typical graph, answering the various questions that come up along the way. Full code is provided in an example database.

Here is a basic Line graph created with the 4D V3 GRAPH command:

Here is how the same graph looks when built in 4D Chart, using the default settings:

Here is how the graph could look after using 4D Chart commands to refine its appearance:

To display a graph with the GRAPH command, you place a variable of type Graph on your form. To display a graph in 4D Chart, you typically start by placing a 4D Chart plug-in area on your form. (You can also display 4D Chart in an external window.)

In the 4D V6 Form Editor, you can drag the "Plug-in Area" object (not the "Chart" object) from the Objects palette to your form. Then double-click the object to bring up the Object Properties dialog. In the Variable tab of that dialog, the Type pop-up menu is already set to "Plug-in Area." In the Plug-in Area pop-up menu below that, you need to specify "_4D Chart." At the top of the dialog, enter the name of the plug-in area's variable. The value of this variable is used as the Area ID in the 4D Chart commands that require it.

The code that creates a graph typically runs from either the form method or an object method. To open a window displaying a graph, this code needs to run in the On Load form event. A new graph could be displayed in an already open window by running the code from interface elements such as buttons or menu bars. To include a graph in a printed report, the code to create the graph should run in the On Printing Detail form event of the report form.

Making a 4D Chart area non-enterable

A significant difference between a 4D Chart area and the graph created by the Graph commands is that the 4D Chart area is, by default, an enterable plug-in area complete with its own interface elements including a menu bar and tool bar. While the GRAPH command's graph area can only be a display-only element on a form, 4D Chart areas can be enterable. Objects can be selected by clicking on them, then 4D Chart's menu bar or tool bar can be used to change or delete them, or to add new objects.

If you only need a graph for display purposes, you may prefer to set the 4D Chart area to be non-enterable, and hide the 4D Chart interface elements.

Setting the second parameter of the CT SET ENTERABLE command to zero makes the 4D Chart area non-enterable. If you choose to do this, it is also a good idea to insert the following line of code after you've created all the objects in the 4D Chart area. It uses the CT SELECT command to deselect all objects, so that if the user does click on one, it won't take on a selected appearance (with handles around its perimeter).

   ` Deselect all objects, so they won't display with handles:
   CT SELECT ($nAreaID;-1;0)

Preventing a small 4D Chart area from displaying as a button

If your 4D Chart area is small (less than 300 pixels wide by 150 pixels high), its default behavior is to display as a large button, instead of as a 4D Chart area. When you click on this button, a 4D Chart external window opens up. This is known as 4D Chart's "button mode." To avoid this, you can either make your 4D Chart area larger, or you can suppress the button mode by setting the optional third parameter of the CT SET ENTERABLE command to the value 1.

Suppressing the Save Document alert

When a form is displayed with the default settings of 4D Chart, upon closing the form, a dialog asks, "Save changes to the 4D Chart document?" If you are presenting a graph for display purposes only, you may prefer to suppress this dialog by setting the fifth parameter of the CT SET PROPERTIES command to zero.

Hiding 4D Chart's interface elements

If you choose to make your 4D Chart area non-enterable, and do not need the interactive features of 4D Chart, your graph display will look less cluttered if you hide 4D Chart's interface elements. This is done with the CT SET DISPLAY command:

   ` Hide 4D Chart interface elements:
   CT SET DISPLAY ($nAreaID;1;0)  ` Hide 4D Chart menu bar
   CT SET DISPLAY ($nAreaID;2;0)  ` Hide Chart tools
   CT SET DISPLAY ($nAreaID;3;0)  ` Hide Object tools
   CT SET DISPLAY ($nAreaID;6;0)  ` Hide Scroll bars
   CT SET DISPLAY ($nAreaID;9;0)  ` Hide Rulers

Specifying the range of the vertical scale

By default, the range of the vertical scale on graphs is set automatically. However, this automatic scaling produces different results in 4D Chart than with the Graph commands of 4D V3. The defaults for the scale divisions are also different. Through code, you can set your own choices for the range of the vertical scale. In the Graph commands, this is done via the ymin and ymax parameters to the GRAPH SETTINGS command. In 4D Chart, depending on whether the values in the vertical scale are numbers or dates, you would use either the CT SET REAL SCALE or CT SET DATE SCALE command. These commands also allow you to set the size of the major and minor divisions along a scale.

Hiding the tick marks along the axes

For a more streamlined appearance, you can use the CT SET AXIS ATTRIBUTES command to hide the tick marks along the horizontal and vertical axis of a graph:

   ` Hide major tick marks along the horizontal axis:
   $nAxis:=0  ` Categories axis
   $nNoChange:=-1  ` Constant for use in 4D Chart parameters
   CT SET AXIS ATTRIBUTES ($nAreaID;$nObjectID;$nAxis;0;0;0;$nNoChange)
   
   ` Hide major tick marks along the vertical axis:
   $nAxis:=2  ` Values axis
   $nNoChange:=-1  ` Constant for use in 4D Chart parameters
   CT SET AXIS ATTRIBUTES ($nAreaID;$nObjectID;$nAxis;0;0;0;$nNoChange)

Displaying dates on the horizontal axis in four-digit year format

If you are using dates for your x-axis and would like them to be displayed with four-digit years, specify the "Short2" date format in the sixth parameter of the CT SET LABEL ATTRIBUTES command:

   ` Set horizontal axis labels to display dates with 4-digit year:
   $nAxis:=0  ` Categories axis
   CT SET LABEL ATTRIBUTES ($nAreaID;$nObjectID;$nAxis;
   $nNoChange;$nNoChange;"Short2";$nNoChange)

Hiding the rectangle around the graph legend

By using the CT SET CHART LINE ATTRIBUTES command with the proper combination of partType and partSpecifics codes, you can set the characteristics of different lines in your graph. To hide the rectangle that is by default drawn around the graph legend, you can change the line color of this border to the color of your background:

   ` Hide the border around the graph legend:
   $nPartType:=2  ` Code for "legend"
   $nColorCode:=CT Index to color (1)  ` White
   $nPartSpecifics:=0
   $nNoChange:=-1  ` Constant for use in 4D Chart parameters
   CT SET CHART LINE ATTRIBUTES ($nAreaID;$nObjectID;
   $nPartType;$nPartSpecifics;$nNoChange;$nColorCode;$nNoChange)

Displaying dotted or colored grid lines

By using the CT SET CHART LINE ATTRIBUTES command with the appropriate partType and partSpecifics codes, you can set the characteristics of the graph grid lines. The pattern parameter can be used to change the default solid lines into dotted lines:

   ` Set the grid lines along the values axis to dotted line pattern:
   $nPartType:=6  ` Code for "major grid lines"
   $nPartSpecifics:=2  ` Code for values axis
   $nPattern:=5  ` Code for dotted line fill
   $nNoChange:=-1  ` Constant for use in 4D Chart parameters
   CT SET CHART LINE ATTRIBUTES ($nAreaID;$nObjectID;
   $nPartType;$nPartSpecifics;$nPattern;$nNoChange;$nNoChange)

To subdue the appearance of grid lines, you may prefer instead to change their color, which is specified in the sixth parameter of the CT SET CHART LINE ATTRIBUTES command:

   ` Color the grid lines along the values axis:
   $nPartType:=6  ` Code for "major grid lines"
   $nPartSpecifics:=2  ` Code for values axis
   $nPattern:=3  ` Code for solid fill
   $nColorCode:=CT Index to color (243)  ` Gray
   CT SET CHART LINE ATTRIBUTES ($nAreaID;$nObjectID;
   $nPartType;$nPartSpecifics;$nPattern;$nColorCode;$nNoChange)

Setting the background color of the graph grid area

To change the background color of the graph grid area, use the CT SET CHART FILL ATTRIBUTES command, specifying partType code 1, for "plot rectangle." For a 2-D graph, the only partSpecifics code you need is 0, for the entire graph grid area. For a 3-D graph, you can use partSpecifics codes 1, 2, and 3 to specify the back, side, and bottom grid areas respectively.

Hiding the point squares on a graph

On a 2D Line graph, the point squares are 150% larger in 4D Chart than they were in 4D V3. If you are displaying closely spaced data on your graph, these large point squares may obscure the lines of your graph. To prevent this, you can either spread the points apart by expanding the size of your graph, or you can use the CT SET CHART OPTIONS command to hide the point squares:

   ` Hide the point squares along the graph curves:
   ARRAY INTEGER($aOptions;3)
   $aOptions{1}:=0  ` Vertical orientation
   $aOptions{2}:=0  ` Stack mode: normal
   $aOptions{3}:=0  ` Make point squares invisible
   CT SET CHART OPTIONS ($nAreaID;$nObjectID;$aOptions)

In 4D Chart's 2D XY graph or in a 3D Spike graph, you can use the CT SET CHART OPTIONS command to select the shape of the point squares. In all other graph types, you cannot change the size or shape of the plotted points.

Changing the colors of the curves on a graph

The CT SET CHART FILL ATTRIBUTES command can be used with the appropriate parameters to set the colors of graph curves. In some graph types, such as 3-D graphs, the color of the outline rule around each graph curve can be set in a similar way with the CT SET CHART LINE ATTRIBUTES command. The following code sets the colors of the graph curves in 4D Chart to approximate the six colors used in the 4D V3 Graph commands:

   ` Set curves in 4D V3 graph colors:
   $nPartType:=8  ` Code for "series"
   $nPattern:=3  ` Code for solid fill
   
   ARRAY LONGINT($aColorCode;6)
   $aColorCode{1}:=CT RGB to color (55512;0;0)  ` Red
   $aColorCode{2}:=CT RGB to color (2570;34952;0)  ` Green
   $aColorCode{3}:=CT RGB to color (65535;63222;1028)  ` Yellow
   $aColorCode{4}:=CT RGB to color (0;41377;65535)  ` Light Blue
   $aColorCode{5}:=CT RGB to color (65535;0;37008)  ` Magenta
   $aColorCode{6}:=CT RGB to color (0;0;65535)  ` Blue
   
   For ($i;1;$nSeries)
      If ($i%6=0)
         $nColorCode:=$aColorCode{6}
      Else
         $nColorCode:=$aColorCode{$i%6}
      End if
      $nPartSpecifics:=$i*100  ` Code for a specific curve on the graph
      CT SET CHART FILL ATTRIBUTES ($nAreaID;$nObjectID;
      $nPartType;$nPartSpecifics;$nPattern;$nColorCode)
   End for 

Converting Proportional Column and Stacked Column graphs to 4D Chart


In the syntax of the Graph commands, Column, Proportional Column, and Stacked Column graphs are three separate graph types. In 4D Chart, these are handled as variations of the Column graph type. To display these Column graph variations in 4D Chart, you specify options with the CT SET CHART OPTIONS command.

Converting an Area graph to 4D Chart


The difference between using the GRAPH command and 4D Chart to create a 2D Area graph is that the GRAPH command stacks the graph curves, whereas 4D Chart's default Area graph does not. The stacked option for a 4D Chart Area graph can be set with the CT SET CHART OPTIONS command.

Converting a Pie chart to 4D Chart


To set the colors of individual pie chart wedges, use the CT SET CHART FILL ATTRIBUTES command. Use partType code 8, which specifies "series." To get the partSpecifics code for an individual pie wedge, multiply its ordinal position (starting clockwise from the twelve-o-clock position) by 100. For example, the partSpecifics code for the second pie wedge would 200.

You can use the same partType and partSpecifics codes with the CT SET CHART LINE ATTRIBUTES command to set the color of the outline around a pie wedge.

The CT EXPLODE PIE command can be used to move specified wedges of a pie chart away from the center of the pie.

In the pie charts created with the GRAPH command, each wedge of the pie is labeled with its value. In 4D Chart, pie charts do not by default include these labels. To display them, use the third parameter of the CT SET VALUE ATTRIBUTES command. Set the value to 1 to display labels inside the wedges, or 2 to display labels outside the perimeter of the pie.

Configuring a Polar graph in 4D Chart


You can set the inside color of the point dots with the CT SET CHART FILL ATTRIBUTES command. For the partType code, use 8 ("series"). For the partSpecifics code, multiply the graph curve's ordinal number by 100. For example, the code for the second curve would be 200.

You can use the same partType and partSpecifics codes with the CT SET CHART LINE ATTRIBUTES command to set the outline color of the point dots.

The CT SET REAL SCALE command can be used to customize the scale that runs along the radius of the graph.

Notes on other graph types


4D Chart's Scatter graph (type code 5) is actually a Line graph, using the option to show only the graphed points, without the lines. To create a Scatter graph in the Chart Wizard, first select "2D Line" from the "Chart type" tab of the Chart Wizard, then select the Scatter graph from the "Chart style" tab.

In the same way, to create a Polar graph in the Chart Wizard, first select "2D XY" from the "Chart type" tab of the Chart Wizard, then select "2D Polar" from the "Chart style" tab.

The example databases


Two example databases are provided with this technical note. "V3GraphToChart" can be opened with 4D V3.5 or higher. This example allows you to view all the types of graphs that can be created using the GRAPH command. Choose Graph Demo from the File menu to display the graphs. All the graph types can be chosen from a pop-up menu. There is also a check box to activate the proportional x-axis option, which is only effective on Line graphs and Scatter graphs. You can convert this database to 4D V6, to compare the look of the graphs.

The second example database, "V6GraphToChart," demonstrates the basic varieties of graphs that can be created with 4D Chart. Chose Graph by 4D Chart from the File menu to open a graph display similar to the other example database. In the pop-up menu, you can choose to view all the standard 4D Chart graph types, as well as several variations that duplicate the other styles possible with the Graph commands. The "Default" radio button displays each graph type as it appears with the default settings of 4D Chart. In the default mode of this example database, after selecting a graph by clicking on it, you can experiment with using the 4D Chart menu bar to modify the graph. Almost all changes you can make with the menu bar can also be made with the 4D Chart commands. Clicking the "Custom" radio button displays a sample of how each graph type can be enhanced with 4D Chart commands.

Summary


4D Chart opens up many creative possibilities, allowing you to create more attractive graphs than with the Graph commands. This technical note introduces the basics of using 4D Chart by explaining how to implement the features of the Graph commands in 4D Chart.

See also

Technical note 98-13, "Displaying Graphs from 4D Chart on the Web," includes another example database that compares the use of the Graph and 4D Chart commands to create the same graph. 4D Chart example databases are also provided with technical notes 98-18 and 98-23.

98-13, Displaying Graphs from 4D Chart on the Web

98-18, Animating Graphs with 4D Chart

98-22, The GRAPH Command in 4D V6

98-23, Real-Time Graphs in 4D Chart

As of this writing, the following documents have the most recent information about 4D Chart. The 4th Dimension User Reference includes seven chapters pertaining to 4D Chart. The 4D Chart commands are documented in the 4D Chart Language Reference.

4D Chart® Language Reference (4D Chart_6_ Lang_Ref.pdf)

4D Chart® Addendum Version 6.0.5 (4D_Chart_605_Addendum.pdf)

4th Dimension® User Reference (4D_6_User_Ref.pdf)

4th Dimension® Language Reference (4D_605_Language_Reference.pdf)


ACI - Documentation Français English German ACI Technical Notes ACI Technical Notes, By Subject Back Previous Next