this simple bar chart doesn't require any image manipulation software on the
server. it's done only in html and uses percentages in tables to show the
chart.
“simple bar chart ” makes use of the built-in PHP functions
count( ) .
01 <?php
02
03 // total width
04 $total_width = 600 ;
05
06 // base color
07 $base_color = 'silver' ;
08
09 // add an array per field to show
10 $graphs = array (
11 array ( 'label' => 'whatever' , 'color' => 'red' , 'amount' => '30' ) ,
12 array ( 'label' => 'more here' , 'color' => 'green' , 'amount' => '36' ) ,
13 array ( 'label' => 'just an example' , 'color' => 'blue' , 'amount' => '82' ) ,
14 array ( 'label' => 'even more' , 'color' => 'orange' , 'amount' => '4' ) ,
15 ) ;
16
17 for ( $x = 0 ; $x < count ( $graphs ) ; $x ++ )
18 {
19 echo '
20 <table width="' . $total_width . '">
21 <tr>
22 <td colspan="2">
23 ' . $graphs [ $x ] [ 'label' ] . '
24 </td>
25 </tr>
26 <tr>
27 <td width="' . $graphs [ $x ] [ 'amount' ] . '%" bgcolor="' . $graphs [ $x ] [ 'color' ] . '">
28 ' . $graphs [ $x ] [ 'amount' ] . '%
29 </td>
30 <td width="' . ( 100 - $graphs [ $x ] [ 'amount' ] ) . '%" bgcolor="' . $base_color . '">
31
32 </td>
33 </tr>
34 </table>' ;
35 }
36
37 ?>