communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "html and code" - download "simple bar chart" - open demo of "simple bar chart"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

html and code - simple bar chart was created/last modified on Wed 12 May 2004 11:19 AM

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.
  
<?php
  
  
// total width
  
$total_width = 600;
  
  
// base color
  
$base_color = 'silver';
  
  
// add an array per field to show
  
$graphs = array(
  array(
'label'=>'whatever', 'color'=>'red', 'amount'=>'30'),
  array(
'label'=>'more here', 'color'=>'green', 'amount'=>'36'),
  array(
'label'=>'just an example', 'color'=>'blue', 'amount'=>'82'),
  array(
'label'=>'even more', 'color'=>'orange', 'amount'=>'4'),
  );
  
  for(
$x = 0; $x < count($graphs); $x++)
  {
      echo
'
  <table width="'
.$total_width.'">
      <tr>
          <td colspan="2">
              '
.$graphs[$x]['label'].'
          </td>
      </tr>
      <tr>
          <td width="'
.$graphs[$x]['amount'].'%" bgcolor="'.$graphs[$x]['color'].'">
               '
.$graphs[$x]['amount'].'%
          </td>
          <td width="'
.(100-$graphs[$x]['amount']).'%" bgcolor="'.$base_color.'">
               &nbsp;
          </td>
      </tr>
  </table>'
;
  }
  
?>

learn more about some of the PHP functions used in this snippet: array, count, echo, for, range, require

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari