# Advanced Graphs and Charts for PHP

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

## Database Interface Script

Here the graphing software is instructed to dynamically read data from a CSV file.

This method allows you to graph data dynamically straight from a CSV file.

The graph above is produced using the "Data Interface Script" method with the following IMG tag:-

<img src="../../graph/vertical-cylinder-graph.php? data=../demo/examples/data/csvdataScript.php& config=../demo/examples/data/csvConfig.php" width="700" height="400" />

The graph data is produced by the interface script and read by the graphing software at runtime:-

./jpowered/demo/examples/data/csvdataScript.php /* * read the csv file */ $csvdata = file('csvData.csv'); $first = TRUE; $dataCount = 1; /* * process each row of the * csv file */ foreach ($csvdata as $datarow) { if ($first) // ignore the first header row { $first = FALSE; } else { /* * extract the temperature value * from each row and write out * the data parameter */ $dataelements = explode(',',$datarow); if (isset($dataelements[1])) { $dataelements[1] = (float)$dataelements[1]; print 'data'. $dataCount .'series1: ' . $dataelements[1] . PHP_EOL; $dataCount++; } } }

With this method the graphing software calls the interface script at runtime and reads the output of the script in the same way that it would read the data from a flat file. This method allows data to be dynamically produced and plotted in real-time.

The settings and styles are set from the information contained in the file:-

./jpowered/demo/examples/data/csvConfig.php

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

If the graph above does display but no data is shown then the most likely cause is that the graph is having trouble connecting to the database server. Ensure that the 'Sample Application' has been set up with the correct DB User credentials.

If you have not yet set up the Sample Application then you can do so here.

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