| Name: | phpMyGraph |
| Version: | 4.0.2 |
| Last version date: | 13-06-2008 |
| Author: | Martijn Beulens |
phpMyGraph is written and maintained by Martijn Beulens. This PHP library is written in PHP5 and has no PHP4 support.
This class can be used to render several types of charts in images.
It can render bar, line and polygon charts from an array of chart data parameters.
Several chart parameters may be configured such as the colors, borders, fonts, etc..
Look at the samples below which show you how to use it.
Download the latest copy of phpMyGraph here
To create a default graph using the default config file you only need to define a data array
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create data array for graph
$data = array
(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>50,
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseVerticalColumnGraph($data);
?>
The code above will output
To create a default graph using the default config file you only need to define a data array
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create data array for graph
$data = array
(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>50,
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseHorizontalColumnGraph($data);
?>
The code above will output
To create a default graph using your own config you need to define a cfg array next to the data array. (All config directives are listed Here)
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create config array for graph
$cfg = array
(
'title'=>'This is my test graph',
'background-color'=>'FFFFFF',
'graph-background-color'=>'FFFFFF',
'font-color'=>'000000',
'border-color'=>'009900',
'column-color'=>'00FF00',
'column-shadow-color'=>'009900',
'column-font-color-q1'=>'000000',
'column-font-color-q2'=>'000000',
'random-column-color'=>1
);
//Create data array for graph
$data = array
(
'jan'=>rand(-20,200),
'feb'=>-40,
'mar'=>rand(20,200),
'apr'=>rand(0,200),
'may'=>rand(0,200),
'jun'=>rand(0,200),
'jul'=>rand(-20,200),
'aug'=>rand(-200,200),
'sep'=>rand(0,200),
'oct'=>rand(-200,200),
'nov'=>rand(0,200),
'dec'=>rand(0,200),
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseVerticalColumnGraph($data,$cfg);
?>
The code above will output
To create a default graph using your own config you need to define a cfg array next to the data array. (All config directives are listed Here)
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create config array for graph
$cfg = array
(
'title'=>'This is my test graph',
'background-color'=>'FFFFFF',
'graph-background-color'=>'FFFFFF',
'font-color'=>'000000',
'border-color'=>'009900',
'column-color'=>'00FF00',
'column-shadow-color'=>'009900',
'column-font-color-q1'=>'000000',
'column-font-color-q2'=>'000000',
'random-column-color'=>1,
'width'=>600
);
//Create data array for graph
$data = array
(
'jan'=>rand(-20,200),
'feb'=>-40,
'mar'=>rand(20,200),
'apr'=>rand(0,200),
'may'=>rand(0,200),
'jun'=>rand(0,200),
'jul'=>rand(-20,200),
'aug'=>rand(-200,200),
'sep'=>rand(0,200),
'oct'=>rand(-200,200),
'nov'=>rand(0,200),
'dec'=>rand(0,200),
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseHorizontalColumnGraph($data,$cfg);
?>
The code above will output
To create a default graph using the default config file you only need to define a data array
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create data array for graph
$data = array
(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>50,
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseVerticalLineGraph($data);
?>
The code above will output
To create a default graph using the default config file you only need to define a data array
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create data array for graph
$data = array
(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>50,
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseHorizontalLineGraph($data);
?>
The code above will output
To create a default graph using your own config you need to define a cfg array next to the data array. (All config directives are listed Here)
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create config array for graph
$cfg = array
(
'title'=>'This is my test graph',
'background-color'=>'FFFFFF',
'graph-background-color'=>'FFFFFF',
'font-color'=>'000000',
'border-color'=>'009900',
'column-color'=>'00FF00',
'column-shadow-color'=>'009900',
'column-font-color-q1'=>'000000',
'column-font-color-q2'=>'000000',
);
//Create data array for graph
$data = array
(
'jan'=>rand(-20,200),
'feb'=>-40,
'mar'=>rand(20,200),
'apr'=>rand(0,200),
'may'=>rand(0,200),
'jun'=>rand(0,200),
'jul'=>rand(-20,200),
'aug'=>rand(-200,200),
'sep'=>rand(0,200),
'oct'=>rand(-200,200),
'nov'=>rand(0,200),
'dec'=>rand(0,200),
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseVerticalLineGraph($data,$cfg);
?>
The code above will output
To create a default graph using your own config you need to define a cfg array next to the data array. (All config directives are listed Here)
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create config array for graph
$cfg = array
(
'title'=>'This is my test graph',
'background-color'=>'FFFFFF',
'graph-background-color'=>'FFFFFF',
'font-color'=>'000000',
'border-color'=>'009900',
'column-color'=>'00FF00',
'column-shadow-color'=>'009900',
'column-font-color-q1'=>'000000',
'column-font-color-q2'=>'000000',
);
//Create data array for graph
$data = array
(
'jan'=>rand(-20,200),
'feb'=>-40,
'mar'=>rand(20,200),
'apr'=>rand(0,200),
'may'=>rand(0,200),
'jun'=>rand(0,200),
'jul'=>rand(-20,200),
'aug'=>rand(-200,200),
'sep'=>rand(0,200),
'oct'=>rand(-200,200),
'nov'=>rand(0,200),
'dec'=>rand(0,200),
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseHorizontalLineGraph($data,$cfg);
?>
The code above will output
To create a default graph using the default config file you only need to define a data array
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create data array for graph
$data = array
(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>50,
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseVerticalPolygonGraph($data);
?>
The code above will output
To create a default graph using the default config file you only need to define a data array
<?php
//Include phpMyGraph class
include_once('phpMyGraph4.0.php');
//Create data array for graph
$data = array
(
'Mon'=>10,
'Tue'=>20,
'Wed'=>30,
'Thu'=>100,
'Fri'=>20,
'Sat'=>10,
'Sun'=>50,
);
//Create new graph
$graph = new phpMyGraph();
//Parse vertical line graph
$graph->parseHorizontalPolygonGraph($data);
?>
The code above will output
All directives
| Directive | Type | Default value | Comment |
|---|---|---|---|
| title | text | Title for graph | |
| width | int | 200 | Width for graph image. (Will be expanded if to small) |
| height | int | 200 | Height for graph image. |
| font-size | int | 2 | Font size (Possible values are 1,2,3,4) |
| background-color | color | FFFFFF | Background color for image. (use HEX value) |
| graph-background-color | color | E2E1E2 | Background color for graph background. (use HEX value) |
| font-color | color | 006699 | Default font color. (use HEX value) |
| column-font-color-q1 | color | 006699 | Font color for column value which is outside the column. (use HEX value) |
| column-font-color-q2 | color | 000000 | Font color for column value which is inside the column. (use HEX value) |
| border-color | color | 006699 | Border color. (use HEX value) |
| column-color | color | 0099CC | Column background color. (use HEX value) |
| column-shadow-color | color | 006699 | Column shadow color. (use HEX value) |
| min-col-width | int | 32 | Minimum column width. |
| background-color-alpha | int | 0 | Alpha for background color. |
| graph-background-color-alpha | int | 0 | Alpha for graph background color. |
| font-color-alpha | int | 0 | Alpha for font color. |
| column-font-color-q1-alpha | int | 0 | Alpha for column value which is outside the column. |
| column-font-color-q2-alpha | int | 0 | Alpha for column value which is inside the column. |
| border-color-alpha | int | 0 | Alpha for border color. |
| column-color-alpha | int | 0 | Alpha for column color |
| column-shadow-color-alpha | int | 0 | Alpha for column shadow color |
| transparent-background | bool | 0 | Sets the background color as transparent color. (use 1) |
| random-column-color | bool | 0 | Generates random color for each column (use 1) |
| disable-legenda | bool | 0 | Disables the display of column legenda text (use 1) |
| disable-values | bool | 0 | Disables the display of column values text (use 1) |
| file-name | text | NULL | Parses image to file |
For comments or refactored versions.
Please send an e-mail to phpmygraph [AT] abisvmm.nl