graphpite
[ class tree: graphpite ] [ index: graphpite ] [ all elements ]
Prev Next
Adding a plotarea

Adding a plotarea

The GraPHPite Tutorial

Adding a plotarea

Afterwards you must create one or more PlotArea(s) to use for plotting. After you have created the GraPHP object you must add all other elements, either directly to the GraPHP object or an object that has a parent-child chain that terminates in the GraPHP object, ie GraPHP->PlotArea->LineChart->add(Marker) (this is not actual code!).

To add a new PlotArea to the Graph do either of the following.

  1. ..
  2. $Graph->add(new PlotArea(), "PlotArea");
  3. ...

or a less compact but perhaps more comprehensible version.

  1. ...
  2. $PlotArea =& new PlotArea();
  3. $Graph->add($PlotArea);
  4. // or
  5. $Graph->add($PlotArea =& new PlotArea());
  6. ...

In the first example by specifying the name "PlotArea" as a second parameter will cause the add function to automatically create a global variable pointing to the newly created object, ie the "new PlotArea()" parameter. This option is included for 2 reasons: 1) It makes the code less cluttered by reducing the number of assignments 2) It reduces the risk of forgetting an "&" (ampersand) after the "=" (equals) sign. The "&" is VERY important, especially if you want to modify/add to the object after the add. Cause PHP 4 assigns by making a copy of the object instead of by reference. So if the "&" is forgotten and you make (some) changes to the created object, they will not be applied to the "added" object because it is another copy. The following pseudo code will demonstrate this:

  1. $A = new A(); // create an instance of the A class and assign it to $A
  2. $B = $A; // assign $A to $B, this makes a COPY of $A and stores it in $B
  3. &$A == &$B;

Line 3 in the above example will evaluate to FALSE, because $B is a COPY of $A and therefore it will NOT refer to the same object (this is pseudo PHP code!).

On the other hand if you did the following:

  1. $A =& new A(); // create an instance of the A class and assign THE REFERENCE to it to $A
  2. $B = &$A; // assign THE REFERENCE of $A to $B
  3. &$A == &$B;

Line 3 in the above example will evaluate to TRUE, because $B is a reference to $A and therefore it will refer to the same object (this is pseudo PHP code!), ie the reference/pointer is the same.

Prev Up Next
Creating the Graph How to use GraPHPite Creating the dataset

Documentation generated on Fri, 12 Nov 2004 08:24:20 +0100 by phpDocumentor 1.3.0RC3