Creating the dataset
After creating (or before) the Image_Graph_PlotArea and Image_Graph, but before
(or in the same "command) you create the specific plot, you need to specify the data to use. This is done
using the Image_Graph_Dataset classes. How to use the datasets depends on the specific type
of set. They are all demonstrated below, starting with the most simple.
Trivial Dataset
The trivial dataset is basically an array which hold (X, Y)
data pairs. All data are added sequentially using Image_Graph_Dataset_Trivial::addPoint().
See the example below:
1 $Dataset =& new Image_Graph_Dataset_Trivial(); // create the dataset 2 $Dataset->addPoint(0, 10); // add point (0, 10) 3 $Dataset->addPoint(1, 17); // add point (1, 17) 4 $Dataset->addPoint("Dog", pi()); // add point (Dog, 3.14159...) 5 ...
|
Random Dataset
Another dataset is one used especially for demonstrational purposes, sinces it provide no
real information, the random dataset. Data points (X, Y) are X as
sequential and Y as a random value.
Function Dataset
It is (often) very usefull to visualize a mathematical function on a graph. To do this
the function dataset is provided. The data points (X, Y) are
evaluated as X is sequential and Y is the function applied to the X value, ie Y = f(X).
The function needs to be a single parameter function and return a single primitive value,
like for instance sin, cos, etc.
The dataset below is an example of how to use a standard function.
The dataset below is an example of how to use a user function.
1 function foo($bar) { 2 return sin($bar)+cos($bar)*$bar; 3 } 4 5 $Dataset =& new Image_Graph_Dataset_Function(-10, 10, "foo", 100); 6 // generate a 100 points using the aFunc function between -10 and 10 7 ...
|
The dataset below is demonstrates the same as the above but using create_function().
Vector Function Dataset
The vector function dataset is in many ways the same as
the function dataset. The main (and basically the only) difference
is that the (X, Y) data is calculated as (fx($T), fy($T)) instead of ($X, f($X)).
The dataset below is an example of how to use a vector function.
1 $Dataset =& new Image_Graph_Dataset_VectorFunction(0, 2*pi(), "cos", "sin", 100); 2 // generate a 100 points on the (cos, sin) curve between 0 and 2*pi 3 // this will produce a perfect circle 4 ...
|
The dataset below is an example of how to use a vector function with 2 user functions.
1 function tcost($t) { return $t*cos($t); } 2 function tsint($t) { return $t*sin($t); } 3 $Dataset =& new Image_Graph_Dataset_VectorFunciton(0, 20, "tcost", "tsint", 100); 4 // generate a 100 points on the (cos, sin) curve between 0 and 20 5 // this will produce a spiral with center in (0, 0) 6 ...
|
Similarly to the function dataset it's possible to use the create_function() to specify
the function-parameters to use.