|
|
|
|
|
|
| |
When you want to compare your data among durations, the first choice is graph. This function will create a bar graph by using only tag table. If your data looks like this:
Month 1 Growth 25%
Month 2 Growth 20%
Month 4 Growth 15%
Month 7 Growth 23%
select all data to array:
$dnum[1]=25, $dnum[2]=20, $dnum[4]=15, $dnum[7]=23
and $allmonth=7 that means you have data until 7th month
then send variable to function graph()
| <?php
$dnum[1]=25;
$dnum[2]=20;
$dnum[4]=15;
$dnum[7]=23;
$allmonth=7;
function graph($allmonth, $dnum) {
$maxdnum=ceil(max($dnum)); //find out the maximal value of array
if ($maxdnum>=50) { $xnum=1; } //set scale of graph to 100%
elseif ($maxdnum>=20) { $xnum=2; } //set scale of graph to 50%
elseif ($maxdnum>=10) { $xnum=5; } //set scale of graph to 20%
elseif ($maxdnum>=5) { $xnum=10; } //set scale of graph to 10%
elseif ($maxdnum>=0) { $xnum=20; } //set scale of graph to 5%
echo "<br><table align=center width=100% border=1>";
echo "<tr bgcolor=cyan align=center><td>Month</td>";
for ($i=1; $i<=100; $i++) { echo "<td></td>"; }
echo "<td>%</td></tr>";
for ($k=1; $k<=$allmonth; $k++) {
if ( !isset($dnum[$k]) ) {
$dnum[$k]='NA'; //set value to missed month
}
echo "<tr align=center><td>$k</td>";
if ($dnum[$k] !='NA') {
$dgraph[$k]=round($dnum[$k]*$xnum);
$rgraph=100-$dgraph[$k];
}else {
$dgraph[$k]=0; $rgraph=100;
}
for ($i=1; $i<=$dgraph[$k]; $i++) { echo "<td bgcolor=red></td>"; }
for ($j=1; $j<=$rgraph; $j++) { echo "<td bgcolor=#dedede></td>"; }
echo "<td>$dnum[$k]</td></tr>";
}
echo "</table>";
}
?> | |
Usage Example
| <?php
graph($allmonth,$dnum);
?> | |
|
|
| Annual Bar Chart Categories : Graphics, PHP, Charts and Graphs | | | Display a bar chart based on random values. Categories : Graphics, PHP, GD image library, Charts and Graphs | | | How to create charts for php using Rchart Categories : PHP, Java, JSP, Graphics, Charts and Graphs | | | HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout. Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs | | | Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs | | | HTML_Graphs provides a simple PHP interface for
creating pure HTML charts. Categories : Graphics, PHP, PHP Classes, Charts and Graphs | | | 3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations. Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs | | | PHP interface class to the eBusiness Charts generatation remote service. Categories : PHP, PHP Classes, Graphics, Charts and Graphs | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | a simple pie-chart in php3 (with gd) Categories : PHP, Graphics, GD image library, Charts and Graphs | | | Retrieve text from table and email to your e-
address in pipe delimited format. Categories : PHP, MySQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | A PHP function to encrypt and decrypt a number or string or a combination of the two. Categories : PHP, Encryption, Security | | | Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate. Categories : Authentication, PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | |
|
|
|