SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Sep 18, 2001, 10:55 #1
- 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.
Brian Smith
www.mylittlechampion.com
-
Sep 18, 2001, 14:36 #2
- 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
-
Sep 18, 2001, 14:48 #3
- 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($img, 255, 0, 0);
imageFilledRectangle($img, 0, 0, $width / 2, $height / 2, $color1);
imageJPG($img);
?>
-
Sep 18, 2001, 19:27 #4
- 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="$num" height="10">
-
Sep 18, 2001, 20:00 #5
- 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.
-
Sep 18, 2001, 21:11 #6
- 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.
Brian Smith
www.mylittlechampion.com
-
Sep 18, 2001, 21:35 #7
- 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.
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.
-
Sep 19, 2001, 17:53 #8
- 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