Content Management Code
  Home arrow Content Management Code arrow Easy Bar Chart
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CONTENT MANAGEMENT CODE

Easy Bar Chart
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2002-11-05

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    guess you already had the Idea of this class. It create a Dynamic Bar Chart of your Dynamic Report, This class can be used for Finance Report, Site Log Report, or any other application that need Bar Chart Auto Generation

    By : hermawan

    <?php
    /***
    Class Name : easyChart Class
    Purpose : Create Simple Bar Chart for Statistic
    Input : Retrieved Data from DB
    Author : Hermawan Haryanto
    Email : hermawan@codewalkers.com
    Website : http://hermawan.com
    Create Date: Sept 28 2001
    Update Date: Nov 27 2002
    ***/
    class easyChart {
    var $title;
    var $width;
    var $height;
    var $bartitle;
    var $barheight;
    var $barwidth;
    var $background;
    var $multiply;
    var $spacebar;
    var $leftspace;
    var $rightspace;
    var $upspace;
    var $bottomspace;
    var $leftlegend;
    var $linecolor;
    var $barcolor;
    var $titlecolor;
    var $legendcolor;
    var $barinfocolor;
    function easyChart () {
    $this->title = "Chart Title";
    $this->background = Array(153,204,102);
    $this->linecolor = Array(240,240,240);
    $this->barcolor = Array(255,255,153);
    $this->titlecolor = Array(111,166,55);
    $this->legendcolor = Array(0,0,0);
    $this->barinfocolor = Array(0,0,0);
    $this->width = 600;
    $this->height = 500;
    $this->barwidth = 20;
    $this->leftspace = 75;
    $this->rightspace = 25;
    $this->upspace = 50;
    $this->bottomspace = 50;
    $this->leftlegend = 10;
    $this->chartlegend = "UG93ZXJlZCBieTogSGVyb";
    }
    function setTitleColor ($color) {
    $this->titlecolor = explode(",",$color);
    }
    function setLegendColor ($color) {
    $this->legendcolor = explode(",",$color);
    }
    function setBarInfoColor ($color) {
    $this->barinfocolor = explode(",",$color);
    }
    function setBarColor ($color) {
    $this->barcolor = explode(",",$color);
    }
    function setLineColor ($color) {
    $this->linecolor = explode(",",$color);
    }
    function setLeftLegend ($leftlegend) {
    $this->leftlegend = $leftlegend;
    }
    function setLeftSpace ($leftspace) {
    $this->leftspace = $leftspace;
    }
    function setRightSpace ($rightspace) {
    $this->rightspace = $rightspace;
    }
    function setTitle ($title) {
    $this->title = $title;
    }
    function setBackground ($color) {
    $this->background = explode (",", $color);
    }
    function setWidth ($width) {
    $this->width = $width;
    }
    function setHeight ($height) {
    $this->height = $height;
    }
    function setBarWidth ($barwidth) {
    $this->barwidth = $barwidth;
    }
    function addBar ($bartitle, $barheight) {
    $this->bartitle[] = $bartitle;
    $this->barheight[] = $barheight;
    }
    function prepare() {
    $this->chartlegend .= "WF3YW4gSGFyeWFudG8gZWFzeUNoYXJ0LmNs";
    $arr = $this->barheight;
    sort ($arr);
    reset ($arr);
    $this->highestvalue = end($arr);
    $this->valueincriement = $this->highestvalue / $this->leftlegend;
    $this->multiply = ( ($this->height-($this->upspace + $this->bottomspace)) / $this->highestvalue);
    $this->spacebar = ( ($this->width - ($this->leftspace + $this->rightspace)) - ($this->barwidth * count($arr) ) ) / (count($arr)+1);
    $this->legendspace = ($this->height - ($this->upspace+$this->bottomspace)) / $this->leftlegend;
    if ($this->barwidth * count($this->barheight) > ($this->width-($this->upspace+$this->bottomspace))) $err = "Bar width is to large";
    if ($err!="") {
    print $err;
    exit;
    }
    }
    function generateChart() {
    $im = ImageCreate($this->width,$this->height);
    $white = ImageColorAllocate($im,255,255,255);
    $background = ImageColorAllocate($im,$this->background[0],$this->background[1],$this->background[2]);
    $black = ImageColorAllocate($im,0,0,0);
    $gray = ImageColorAllocate($im,100,100,100);
    $linecolor = ImageColorAllocate($im,$this->linecolor[0],$this->linecolor[1],$this->linecolor[2]);
    $barcolor = ImageColorAllocate($im,$this->barcolor[0],$this->barcolor[1],$this->barcolor[2]);
    $titlecolor = ImageColorAllocate($im,$this->titlecolor[0],$this->titlecolor[1],$this->titlecolor[2]);
    $legendcolor = ImageColorAllocate($im,$this->legendcolor[0],$this->legendcolor[1],$this->legendcolor[2]);
    $barinfocolor = ImageColorAllocate($im,$this->barinfocolor[0],$this->barinfocolor[1],$this->barinfocolor[2]);
    @ImageFilledRectangle($im,0,25,$this->width,$this->height-15,$background);
    @ImageFilledRectangle($im,1,26,$this->width-2,$this->height-16,$white);
    @ImageFilledRectangle($im,2,27,$this->width-3,$this->height-17,$background);
    @ImageFilledRectangle($im,$this->leftspace,$this->upspace-10,$this->width-$this->rightspace,$this->height-($this->bottomspace-20),$white);
    $titlewidth = strlen($this->title) * ImageFontWidth(5);
    $titlexpos = ($this->width - $titlewidth)/2;
    @ImageString ($im, 5, $titlexpos, 5, $this->title, $titlecolor);
    @ImageString ($im, 1, 0, $this->height - 10, base64_decode($this->chartlegend."YXNzIC0gaHR0cDovL2hlcm1hd2FuLmRtb25zdGVyLmNvbSAtIEdQTA=="), $black);
    for($i=0;$i<=$this->leftlegend;$i++){
    $legendx = 5;
    $legendy = $this->upspace + ($this->legendspace * $i) - 6;
    @ImageString($im, 2, $legendx, $legendy, $this->highestvalue-($this->valueincriement*$i), $legendcolor);
    @ImageLine ($im, $this->leftspace, $legendy+6, $this->width - $this->rightspace, $legendy+6, $linecolor);
    }
    for($i=0;$i<count($this->barheight);$i++){
    $j=$i+1;
    $x1 = ($j * $this->spacebar) + ($i * $this->barwidth) + $this->leftspace;
    $y1 = $this->height - ($this->barheight[$i]*$this->multiply) - $this->upspace;
    $x2 = $x1 + $this->barwidth;
    $y2 = $this->height - $this->bottomspace;
    $bartitlewidth = strlen($this->bartitle[$i]) * ImageFontWidth(2);
    $centerofbar = $x1 + ($this->barwidth / 2);
    $bartitlex = $centerofbar - ($bartitlewidth/2);
    $bartitley = $y2 + 5;
    @ImageFilledRectangle($im, $x1, $y1, $x2, $y2, $barcolor);
    @ImageString($im, 2, $bartitlex, $bartitley, $this->bartitle[$i], $barinfocolor);
    }
    @ImageJPEG($im);
    @ImageDestroy($im);
    }
    };

    // HERE IS THE EXAMPLE TO USE THE CHART CLASS
    $chart = new easyChart(); // Object initialized
    $chart->setTitle("This is my Bar Chart Title"); // Title of Chart
    $chart->setBackground("153,204,102"); // Background of chart [opt]
    $chart->setLineColor("225,225,225"); // Line color separator [opt]
    $chart->setBarColor("255,255,153"); // Bar color [opt]
    $chart->setTitleColor("111,166,55"); // Color Title [opt]
    $chart->setLegendColor("0,0,0"); // Legend Color [opt]
    $chart->setBarInfoColor("0,0,0"); // Bar Info Color [opt]
    $chart->setWidth(600); // Width of Chart
    $chart->setHeight(500); // Height of Chart
    $chart->setBarWidth(20); // Bar Width
    $chart->setLeftSpace(75); // Left Space
    $chart->setRightSpace(25); // Right Space
    $chart->setLeftLegend(10); // Left Legend

    $chart->addBar("Jan",12000000); // Sample content of chart
    $chart->addBar("Peb",15000000);
    $chart->addBar("Mar",10000000);
    $chart->addBar("Apr",9000000);
    $chart->addBar("Mei",18000000);
    $chart->addBar("Jun",12000000);
    $chart->addBar("Jul",160000);
    $chart->addBar("Ags",14000000);
    $chart->addBar("Sept",12000000);
    $chart->addBar("Okt",17000000);
    $chart->addBar("Nop",14000000);
    $chart->addBar("Des",9000000);

    $chart->prepare(); // Chart Preparation
    $chart->generateChart(); // Chart Generation
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Content Management Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Best Practices: The Integrated Project and Portfolio Management Platform.

    Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan.
    FREE! Go There Now!


    NEW! BlammoSplat: Build a community Web site of OpenLaszlo animations, Part 3: The community animation

    Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    FREE! Go There Now!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    CONTENT MANAGEMENT CODE ARTICLES

    - V2 CMS - Content Management System
    - VSNS Lemon
    - Country List For Forms Using SQL
    - eggblog
    - Table generation class
    - STP Simple Template Parser
    - class Vision_To_Form_Elements
    - Cascade Drop Down
    - Cura - CMS
    - Syntax Desktop
    - 216 color table
    - Simple Mini Poll class library (SimPoll)
    - Regex Generator
    - Siteseed
    - Company WebSite Builder PRO





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT