Miscellaneous Code

  Home arrow Miscellaneous Code arrow Draw Bargraphs using GD
MISCELLANEOUS CODE

Draw Bargraphs using GD
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2003-07-18

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    Basic form to enter name & marks of six students. Submitting will draw a bargraph. Save the PHP file as "gengraphs.php"

    By : nazly

    <?php

    if($t1){

    header("Content-type: image/jpeg");

    $imPoint=ImageCreate(400,425);
    $bgColor=ImageColorAllocate($imPoint,255,255,255);
    $stColor=ImageColorAllocate($imPoint,0,0,0);
    $color[0]=ImageColorAllocate($imPoint,255,0,0);
    $color[1]=ImageColorAllocate($imPoint,0,255,0);
    $color[2]=ImageColorAllocate($imPoint,0,0,255);
    $color[3]=ImageColorAllocate($imPoint,255,0,255);
    $color[4]=ImageColorAllocate($imPoint,0,255,255);
    $color[5]=ImageColorAllocate($imPoint,255,255,0);
    for($i=0;$i<11;$i++){
    ImageString($imPoint,2,5,220-($i*20),$i*10,$stColor);
    }
    for($i=0;$i<6;$i++){
    $total=2*$stMarks[$i];
    ImageFilledRectangle($imPoint,50+($i*50),225-$total,75+($i*50),225,$color[$i]);
    ImageString($imPoint,3,55+($i*50),225-$total-15,$stMarks[$i],$stColor);
    ImageFilledREctangle($imPoint,110,260+($i*25),125,275+($i*25),$color[$i]);
    ImageString($imPoint,3,150,260+($i*25),$stName[$i],$stColor);
    }
    ImageLine($imPoint,25,225,350,225,$stColor);
    ImageLine($imPoint,25,10,25,225,$stColor);
    ImageRectangle($imPoint,100,250,250,410,$stColor);
    ImageJPEG($imPoint);
    ImageDestroy($imPoint);
    }
    else{
    echo "This is just a sample script as values are not validated. Make sure you enter integer values on the marks text box<br>";
    echo "<form name=\"a\" action=\"gengraphs.php\" method=\"post\"><input type=\"hidden\" name=\"t1\" value=\"1\">";
    for($i=0;$i<6;$i++)
    {
    $textVal=$i+1;
    echo "Student Name : <input type=\"text\" name=\"stName[$i]\" value=\"Name$textVal\" maxlength=\"10\"> Marks : <input type=\"text\" name=\"stMarks[$i]\" value=\"0\" maxlength=\"3\"><br>";
    }
    echo "<input type=\"submit\" value=\"Draw Graph\"></form>";
    }
    ?>
    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 Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap