Chapter 13. Getting hold of the data to be displayed

Table of Contents

13.1. Static data
13.2. Reading data from a file
13.3. Sending data to a graph script with URI arguments (GET and POST)
13.3.1. Using GET arguments
13.3.2. Using a POST request
13.4. Reading data from a database
13.5. Reading binary data from a file
13.6. Different types of NULL data handling
13.7. Troubleshooting input data

The initial obstacle that must be negotiated is to get hold of the data to be displayed since the library itself is completely agnostic to where the data comes from. The library will use data supplied in one or more arrays and it is up to the user of the library to get hold of the data to populate these arrays with proper data. In principle the data can come from one of the following places

  1. Hard-coded data in the script. This is the least flexible and can only really be recommended for examples and really static data.

  2. Data stored in plain text files.

  3. Data stored in binary format in flat files.

  4. Data stored in a database

  5. Data sent to the script via URI parameter passing (either GET or POST HTTP constructs can be used).

In the following sections we will shortly discuss each of these methods.


The library assumes that the data available in an array that starts with index 0

13.1. Static data

This is the simplest way and consists of only specifying the data in one or several usual PHP arrays directly in the graph script. For example to specify data for a Pieplot one could use the following constructions

$data = array(1,8,5,4,12,18);
$pieplot = new PiePlot ($data);

This is the method used for all examples under the "Example/" directory.