# Advanced Graphs and Charts for PHP

- Graph Home
- Pricing / License Options
- Online Demos
- Documentation
- Tutorials

# Custom Data Function

This feature allows you to create your own custom PHP Data Script function. The function will be included at run time and used by the graph to acquire the data.

This method provides enormous flexibility for the data acquisition process. All PHP Global variables ($_REQUEST, $_GET, $_POST, $_SESSION etc) are available to be used within the data function.

A custom data script is specified via the parameter "datascript". For example if your data script is in a file datascript.php then your <IMG> tag would be:-

<img src="http://www.domain.com/jpowered/graph/[GRAPH-STYLE]? datascript=[path_to_datascript_file]/datascript.php& config=[url_to_config]" width="500" height="400" />
The [path_to_datascript_file] should be a filesystem file path to the data function file. If a relative file path then keep in mind that this will be relative to the location of the graph software and NOT the page which contains the IMG tag.

The data script must be valid PHP code and should contain at least the following function:-

function datascript () { return $lines; }

where $lines is a string array containing the data parameters and values.

The contents of the string array should be the format:-

> dataNseriesM: [value]

where N represents the position of the data item in the series and M represents the series number.

For example, for 3 series of data each containing 6 points the string array should contain:-

data1series1: 30 data2series1: 20 data3series1: -10 data4series1: 40 data5series1: 50 data6series1: 60 data4series2: 40 data5series2: 50 data6series2: 60 data1series3: 100 data2series3: 50 data3series3: -25 data4series3: 75 data5series3: 125 data6series3: 150

Note: The data script should under no circumstances write out any information via the print or echo functions. This would cause the production of the graph image to fail.

The full function would look like this:-

function datascript () { $lines = array(); $lines[] = 'data2series1: 20'; $lines[] = 'data3series1: -10'; $lines[] = 'data4series1: 40'; $lines[] = 'data5series1: 50'; $lines[] = 'data6series1: 60'; $lines[] = 'data4series2: 40'; $lines[] = 'data5series2: 50'; $lines[] = 'data6series2: 60'; $lines[] = 'data1series3: 100'; $lines[] = 'data2series3: 50'; $lines[] = 'data3series3: -25'; $lines[] = 'data4series3: 75'; $lines[] = 'data5series3: 125'; $lines[] = 'data6series3: 150'; return $lines; }

This is a trivial example but as you can see it is now possible to create a function which will construct the data array based upon any parameter held in $_SESSION or other Global. This method can also be used to pull data from a database.

Further information and examples can found in the Online Tutorials here »

« back to Graph Data

### Also see:-

Configuration Options and Parameters »

Package Index

Demo Index

Documentation

Troubleshooting Guide

Support

#### Documentation Contents

Adding Graphs to Web Pages

Configuration Options and Parameters

Supplying the Graph with Data

Sample Image Tags

#### Database Connections

Database Information method

Custom Data Function

more Documentation Online here