Can PHP draw graphs? Pie, Bar, Line graphs? if yes, how? pls help..thanks![]()
| SitePoint Sponsor |
Can PHP draw graphs? Pie, Bar, Line graphs? if yes, how? pls help..thanks![]()



Yes, but you need a graphing library. The one i use which can do all the graphs you've just described is called JPgraph. You can find it at:Originally Posted by cachobong
http://www.aditus.nu/jpgraph
Its farily easy to you, its free. Just download the library and depending on what graph your creating just include that particular file in your code. It takes a little bit of adjusting if your not used to OOP, but there are very easy to tweak examples in the manual. Give it a try, if it doesnt work come back here and people will be able to lend a hand.
thanks everybody! i will![]()
hmm..i already download it
this error message is displayed when i tried to run 1 of the examples.
"Notice: Use of undefined constant IMG_PNG - assumed 'IMG_PNG' in C:\Public\jpgraph\src\jpgraph.php on line 336
JpGraph Error This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)"
what does it mean? what should i do?
can u show me a site that uses gd?
There is also a PEAR class for creating graphs and plots, but I don't think you will find anything better than JPGraph...



What version of PHP are you running? Im not sure which version started bundling GD, but if yours doesnt have it included thats why it wont work? Are you testing it on your localhost or on your live site?Originally Posted by cachobong



cachobong,
I just sent you a PM with a couple examples from my site.
m using my local host...its PHP 5.0 so i downloaded the JpGraph 2.x i tried to include php_gds2.dll but now all the images wont load...but no error appearedOriginally Posted by vhogarth



did u make sure you downloaded the jpgraph that was compatible with php5.0? I think the last time i checked there was a different version for 5.0Originally Posted by cachobong
EDIT: It seems like you downloaded the right version with 2.x.. Not sure whats up.
it works already! thanks! i have 2 last questions.Originally Posted by vhogarth
1. how do i embed it in my php page in the location that i want.
2. how do i use japanese fonts..
thanks very much vhogarth!



its a two part process to embed the graph in your script. First you have to create a .php file that creates the graph (sets up the dimension, type of graph, colors, axis labeling, etc) and the other part is an image tag in the page you want the graph displayed that feeds the graph script the input.Originally Posted by cachobong
Here we go:
ON the page where you want your graph to show you have to specify the path to your script that generates it and pass variables to the script that way like so:
<img src="mypiegraph.php?var1=$variable1&var2=$variable2">
Now in the script called "mypiegraph.php" you have to GET the variables
One "trick" i use to pass a bunch of data to the graph when im tyring to plot a line graph with 20+ x/y coordinates is to make variable1 a string of values seperated by a dashPHP Code:$var1=$_GET['var1'];
$var2=$_GET['var2'];
//now you can use $var1 and $var two as some values for your graph, for example an x,y coordiante.
example:
$variable1="1-2-3-4-5-6-7-8-9-10";
$variable2="1-2-3-4-5-6-7-8-9-10";
So using those two variables i've passed 20 values to the graphing script. In order to extract each value you have to use the explode() function.
$str=explode('-',$variable1);
$str[0]=1;
$str[1]=2;
etc. etc.
Hope that helps you out.
As far as the Japanese fonts I cant help you much there. I dont know japanese, nor have i ever used any language other than english while developing.. Good luck, post back your progress if you make some headway with the language, someone else could probably use it.
thanks vhogarth u have helped a lot! m still finding ways to use the japanese language! and for anyone out there who knows! pls help! its for all of us! thanks!



Thats good to hear! Were you at least able to get the graphs working?Originally Posted by cachobong
Bookmarks