graphpite
[ class tree: graphpite ] [ index: graphpite ] [ all elements ]
Prev Next
Creating the dataset

Creating the dataset

The GraPHPite Tutorial

Creating the dataset

After creating (or before) the PlotArea and GraPHP, 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 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 TrivialDataSet is basically an array which hold (X, Y) data pairs. All data are added sequentially using DataSet::addPoint(). See the example below:

  1. $DataSet =& new TrivialDataSet(); // 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 RandomDataSet. Data points (X, Y) are X as sequential and Y as a random value.

  1. $DataSet =& new RandomDataSet(100, 10, 200);
  2. // generate a random 100 points between 10 and 200
  3. ...

Function Dataset

It is (often) very usefull to visualize a mathematical function on a graph. To do this the FunctionDataSet 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.

  1. $DataSet =& new FunctionDataSet(0, 20, "sin", 100);
  2. // generate a 100 points on the sine curve between 0 and 20
  3. ...

The dataset below is an example of how to use a user function.

  1. function aFunc($X) {
  2. return sin($X)+cos($X)*$X;
  3. }
  4. $DataSet =& new FunctionDataSet(-10, 10, "aFunc", 100);
  5. // generate a 100 points using the aFunc function between -10 and 10
  6. ...

The dataset below is demonstrates the same as the above but using create_function().

  1. $DataSet =& new FunctionDataSet(-10, 10,
  2. create_function('$X', 'return sin($X)+cos($X)*$X;'), 100);
  3. // generate a 100 points using the aFunc function between -10 and 10
  4. ...

Vector Function Dataset

The VectorFunctionDataSet is in many ways the same as the FunctionDataSet. 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 VectorFunctionDataSet(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.  
  5. ...

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 VectorFunctionDataSet(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.  
  7. ...

Similarly to the function dataset it's possible to use the create_function() to specify the function-parameters to use.


Prev Up Next
Adding a plotarea How to use GraPHPite Adding plots

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