# Advanced Graphs and Charts for PHP

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

## Utilising Request Parameters

In this example we again use the included data function method but this time we pass a request parameter through on the IMG tag. The data function will then produce the graph data based on the value of the request parameter.

This method has a variety of uses including displaying graph data dynamically based upon user form selection.

Here is the IMG tag which invokes the graphing software which dynamically creates the graph image at page load time.

<img src="../../graph/vertical-cylinder-graph.php? datascript=../demo/examples/data/dataFunctionParams.php& config=../demo/examples/data/configFile.txt& customParam=8" width=700 height=400 />

Note the extra parameter 'customParam=8' on the IMG tag URL. This is used by the data function to create the data for the chart.

Here we tell the software to load the configuration options from the file configFile.txt and include the data function dataFunctionParams.php (code below)

/* * The graphing software will look for a function named datascript() * at runtime. If found the graph will call this to acquire the * graph data. */ function datascript () { /* * Create the Data Array * * Here we demonstrate how the graphs can be used to display * data based upon the value of request parameters. * * In this trivial example we use the value of a request * parameter to generate the data values. * */ $dataArray = array('series1' => array(50*$_REQUEST['customParam'], 75*$_REQUEST['customParam'], 125*$_REQUEST['customParam'], 430*$_REQUEST['customParam']), 'series2' => array(200*$_REQUEST['customParam'], 210*$_REQUEST['customParam'], 260*$_REQUEST['customParam'], 240*$_REQUEST['customParam']), 'series3' => array(830*$_REQUEST['customParam'], 740*$_REQUEST['customParam'], 620*$_REQUEST['customParam'], 320*$_REQUEST['customParam'])); /* * Convert the data into the array format required * by the graphing software * * The format required is a one dimensional array * which contains a text for each line of data. * */ $dataLines = array(); /* * write out the data in the format required for the graphing software */ foreach ($dataArray['series1'] as $dataIndex => $dataValue) { $dataLines[] = 'data' . ($dataIndex+1) . 'series1: ' . $dataValue; } foreach ($dataArray['series2'] as $dataIndex => $dataValue) { $dataLines[] = 'data' . ($dataIndex+1) . 'series2: ' . $dataValue; } foreach ($dataArray['series3'] as $dataIndex => $dataValue) { $dataLines[] = 'data' . ($dataIndex+1) . 'series3: ' . $dataValue; } /* * return the $dataLines array to the * graphing software */ return $dataLines; }

Note: if a closing PHP tag (?>)is added at the end of the data function file then it is vital that no characters appear after that tag. If even a space character exists then the graphing image will not be produced. It is recommend that the closing PHP tag is omitted.

Note: the URLs supplied for both the configuration and data are relative URLs. The URLs are relative to the location of the graphing software and NOT this page.

If the graph does not display then see the Troubleshooting guide for details on how to resolve the problem.

Package Index

Documentation

Troubleshooting Guide

Support

#### Examples

- Graphing Data from files
- Data from external scripts
- Custom data function
- Utilising request parameters
- Plotting data from a database
- Database interface scripts
- Multiple Scales, text and images
- Graphing CSV files

#### Basic Chart Styles

- Pie Charts
- X-Y Scatter Graphs
- Bubble Charts
- Area Graphs
- Line Graphs

#### Bar Graphs

- Vertical Bar Graphs
- Stacked Vertical Bar Graphs
- Horizontal Bar Graphs
- Stacked Horizontal Bar Graphs

#### Cylinder Charts

- Vertical Cylinder Graphs
- Stacked Vertical Cylinder Graphs
- Horizontal Cylinder Graphs
- Stacked Horizontal Cylinder Graphs

#### Combination Charts

- Area and Stacked Vertical Bar Graph
- Area and Vertical Bar Graph
- Line and Stacked Vertical Bar Graph
- Line and Vertical Bar Graph