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.
- ..
- $Graph->add(new PlotArea(), "PlotArea");
- ...
or a less compact but perhaps more comprehensible version.
- ...
- $PlotArea =& new PlotArea();
- $Graph->add($PlotArea);
- // or
- $Graph->add($PlotArea =& new PlotArea());
- ...
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:
- $A = new A(); // create an instance of the A class and assign it to $A
- $B = $A; // assign $A to $B, this makes a COPY of $A and stores it in $B
- &$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:
- $A =& new A(); // create an instance of the A class and assign THE REFERENCE to it to $A
- $B = &$A; // assign THE REFERENCE of $A to $B
- &$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.