SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I display results in a graph?

    I am including a survey form on my site. I'm going to take input from radio buttons and update a corrosponding column by adding 1 to the value in a MySql table using PHP. I can display the results of all the responses as a numericial value but I also want to display these results in a graphical bar chart. Can anyone give me information on how to do this? Thanks.

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can create your graphics on fly with php, first check if you have GD support enabled (with phpinfo()).
    If so, you can use GD's graphics primitives to draw from lines, rectangles to TTF text.

    Paul

  3. #3
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for example, try

    PHP Code:
    <?php 
      $width  
    100;
      
    $height 100;

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

      
    $img    imageCreate($width$height);
      
    $color1 imageColorAllocate($img25500);
      
    imageFilledRectangle($img00$width 2$height 2$color1);
      
    imageJPG($img);
    ?>

  4. #4
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't tried this, nor do I have any idea if it will work, but why not create a small image (10x1 pixels), put the color or design of the graph you want, then put the submitted variable between the width tag.

    Like so:
    PHP Code:
    <img src="graph.gif" width="$numheight="10"
    And if they vote 10, or something, the graph extends to ten. Like I said, I have no idea what you are trying to do.

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    he's trying to create an image on the fly.
    not just stretch (cause that's all what your saying would) a current one.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  6. #6
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. Both ideas seem very straight foward. I'll try them and see what I get.

  7. #7
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Defender1
    he's trying to create an image on the fly.
    not just stretch (cause that's all what your saying would) a current one.
    I disagree. Unless I missed something, I don't think he said he was trying to create an image on the fly. He said he had a survey script...which is the ideal script to use a "stretched" image for. The effect is much simpler, puts less strain on the server, doesn't take as long, I'd imagine, and doesn't require that his host/server have the proper image-manipulation tools enabled (I think they can be turned off).

    However, I would recommend creating three graphics in all...one for each "end" of the bar, and one in the middle to be stretched, so that the graphic looks more seamless.

  8. #8
    SitePoint Addict lveale's Avatar
    Join Date
    Jun 2001
    Location
    Dublin
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    poll

    I've used the 10x1 pixel method before and it's worked a treat. I also used the alt tag to describe the image, as I had to conform to XHTML1.0 :

    Code:
    <img src="graph_pix.gif"
     height= "10" 
     width="<?=$perc2?>" 
     alt="<?=$perc2?>% of <?=$totalvotes?> votes" />


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •