SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: Graphs in PHP

  1. #1
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Graphs in PHP

    Can PHP draw graphs? Pie, Bar, Line graphs? if yes, how? pls help..thanks

  2. #2
    SitePoint Enthusiast SecondV's Avatar
    Join Date
    Jan 2006
    Location
    Kentucky
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Evangelist vhogarth's Avatar
    Join Date
    Nov 2003
    Location
    Taxachussets
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cachobong
    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:
    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.

  4. #4
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks everybody! i will

  5. #5
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can u show me a site that uses gd?

  7. #7
    SitePoint Evangelist spinmaster's Avatar
    Join Date
    Mar 2005
    Posts
    456
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is also a PEAR class for creating graphs and plots, but I don't think you will find anything better than JPGraph...

  8. #8
    SitePoint Evangelist vhogarth's Avatar
    Join Date
    Nov 2003
    Location
    Taxachussets
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cachobong
    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?
    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?

  9. #9
    SitePoint Evangelist vhogarth's Avatar
    Join Date
    Nov 2003
    Location
    Taxachussets
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cachobong,

    I just sent you a PM with a couple examples from my site.

  10. #10
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vhogarth
    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?
    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 appeared

  11. #11
    SitePoint Evangelist vhogarth's Avatar
    Join Date
    Nov 2003
    Location
    Taxachussets
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cachobong
    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 appeared
    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.0

    EDIT: It seems like you downloaded the right version with 2.x.. Not sure whats up.

  12. #12
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally 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.0

    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.

    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!

  13. #13
    SitePoint Evangelist vhogarth's Avatar
    Join Date
    Nov 2003
    Location
    Taxachussets
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cachobong
    it works already! thanks! i have 2 last questions.

    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.

    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

    PHP 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. 
    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 dash

    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.

  14. #14
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  15. #15
    SitePoint Evangelist vhogarth's Avatar
    Join Date
    Nov 2003
    Location
    Taxachussets
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cachobong
    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?


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
  •