PHP Classes
Icontem

File: example_bar.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Igor Feghali  >  Bar and Line Point Chart  >  example_bar.php  
File: example_bar.php
Role: Example script
Content type: text/plain
Description: Bar Chart
Class: Bar and Line Point Chart
Render bar and line charts as images
 

Contents

Class file image Download
<?

/* #INFO############################################
Author: Igor Feghali
Email: ifeghali@interveritas.net
################################################# */

/* #FILE DESCRIPTION################################
Example for the bar graph
################################################# */

// #INCLUDE#########################################
require("charts.class.php");
// #################################################

// #FUNCTIONS#######################################
function factors($n)
{

    
$div = Array(1);

    for (
$i=1$i<= ($n/2); $i++)
        if (
$n $i == 0)
            
$div[] = $i;

    
$div[] = $n;

    return 
$div;
}

function 
hasAconvenientDiv($div)
{
    
$divs = Array(8,7,6,5,4);
    foreach (
$divs as $k => $v)
    if (
in_array($v,$div))
        return 
$v;
    return 
0;
}
// #################################################

// #INSTANTIATING CLASS#############################
$g = new chart;
// #################################################

// #X ELEMENTS######################################
$elemx = Array();
$elemx[] = "VENDOR A";
$elemx[] = "VENDOR B";
$elemx[] = "VENDOR C";
$elemx[] = "VENDOR D";
$elemx[] = "VENDOR E";
$elemx[] = "VENDOR F";
$elemx[] = "VENDOR G";
// #################################################

// #Y ELEMENTS######################################
$elemy = Array();
$elemy[] = 6.74;
$elemy[] = 9.38;
$elemy[] = 26.69;
$elemy[] = 11.32;
$elemy[] = 26.55;
$elemy[] = 12.80;
$elemy[] = 24.34;
// #################################################

// #BIGGEST Y ELEMENT###############################
$ymax ceil(max($elemy));
// #################################################

// #FINDING A CONVENIENT SCALE FOR Y AXIS###########
if ($ymax 8)
{
    do
    {
        
$div factors($ymax);
        
$ymax++;
    } while (!(
$scale hasAconvenientDiv($div)));

    
$ymax--;
}
// #################################################


// #POPULATING GRAPH################################
foreach ($elemy as $k => $v)
{
    
$g->xValue[] = $elemx[$k];
    
$g->DataValue[] = $v;
}
// #################################################

// #SETTING GRAPH PARAMETERS########################
$g->Title "Example Bar Graph";
$g->SubTitle "Subsidiary A";
$g->Width = (count($elemx)*45) + 75;
$g->Height 300;

$g->xCount count($elemx);
$g->xCaption "Sum: ".array_sum($elemy);
$g->xShowValue TRUE;
$g->xShowGrid TRUE;

$g->yCount $scale;
$g->yCaption "Today Sales (thousands)";
$g->yShowValue TRUE;
$g->yShowGrid FALSE;

$g->DataDecimalPlaces 2;
$g->DataMax $ymax;
$g->DataMin 0;
$g->DataShowValue TRUE;
// #################################################

// #ITS DRAWING TIME################################
$g->MakeBarChart();
// #################################################

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products