Drawing graphs in PHP with JpGraph
“JpGraph is an Object-Oriented Graph creating library for PHP >= 5.1 The library is completely written in PHP and ready to be used in any PHP scripts (both CGI/APXS/CLI versions of PHP are supported).“
If you want to draw graphs in PHP, JpGraph is a good choice. Very easy to use yet powerful.
Installation
Here I suppose you have a public_html directory in your HOME and your PHP scripts are in public_html.
Download the latest jpgraph archive, put it in ~/public_html/lib and extract it. Now you will have a directory like ~/public_html/lib/jpgraph-3.5.0b1. Put a symbolic link on it with a simpler name:
cd ~/public_html/lib ln -s jpgraph-3.5.0b1 jpgraph
Verify if the directory jpgraph has the correct permissions. Directories must be 755, while files must be 644. To correct permissions, you can use this script:
#!/bin/bash # setjog_here.sh # # place it in ~/public_html/lib/jpgraph and launch it # it'll set the permissions recursively find . -type d -print0 | xargs -0 chmod 755 find . -type f -print0 | xargs -0 chmod 644 chmod 755 . chmod u+x $0
Test an example
Copy ~/public_html/lib/jpgraph/src/Examples/example0.php to ~/public_html. Modify the include lines:
# original:
#require_once ('jpgraph/jpgraph.php');
#require_once ('jpgraph/jpgraph_line.php');
# new:
require_once ('lib/jpgraph/src/jpgraph.php');
require_once ('lib/jpgraph/src/jpgraph_line.php');
Now call this file from your browser. The URL must be similar to this: http://localhost/~jabba/example0.php.
Troubleshooting
You might get an error saying “The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.“
Don’t worry. Open the file ~/public_html/lib/jpgraph/src/gd_image.inc.php, find the function SetAntiAliasing and comment this line out like this:
// JpGraphError::RaiseL(25128);//('The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.')
Update (20110215): Comment out just this line, not the whole function :)
This is a quick fix; we disabled antialiasing.
This subsection was updated, the original text was not clear. Thanks to Jon R. for pointing that out.
Leave a Reply Cancel reply
Blog Stats
- 313,248 hits
Random Post
Recent Posts
Tags
Categories
Blogs that I follow
Archives
- May 2013 (9)
- April 2013 (20)
- March 2013 (10)
- February 2013 (7)
- January 2013 (26)
- December 2012 (18)
- November 2012 (13)
- October 2012 (9)
- September 2012 (8)
- August 2012 (7)
- July 2012 (3)
- June 2012 (9)
- May 2012 (16)
- April 2012 (32)
- March 2012 (18)
- February 2012 (17)
- January 2012 (12)
- December 2011 (8)
- November 2011 (18)
- October 2011 (18)
- September 2011 (32)
- August 2011 (13)
- July 2011 (16)
- June 2011 (6)
- May 2011 (14)
- April 2011 (30)
- March 2011 (45)
- February 2011 (42)
- January 2011 (28)
- December 2010 (14)
- November 2010 (29)
- October 2010 (15)
- September 2010 (5)
apology make the changes indicated, but nevertheless an error. thereafter. Commenting after the fuction SetAntiAliasing
Fatal error: Call to undefined method RotImage: SetAntiAliasing () in / var / www / vhosts / irony / impresiondigitalig.com / httpdocs / omar / jpgraph / themes / UniversalTheme.class.php on line 85.
ready … i think that to uncomments whole function, ..jeje i´m sorry… uncomment only that line
// JpGraphError::RaiseL(25128);//(‘The function imageantialias() is not available in your PHP installation. Use the GD version that comes with PHP and not the standalone version.’)
Thanks a lot!!
Thanks!!!!
To fix the issue. Just overwrite the function
imageantialiasIn
jpg-config.inc.php :define('ANTIALIASING', false); if(!ANTIALIASING) { function imageantialias($image, $enabled) { return true; } }Definitely better then writing directly into 3rd party libs core classes. Even better: function_exists(‘imageantialias’) so no need to manually set a constant.
Combined the solutions of Guillaume and Joerx:
if(!function_exists('imageantialias')) { function imageantialias($image, $enabled) { return false; } }My function returns false for rather than true for enabled, to avoid using the function in other calls within the library.
Hi, The comment about uncommenting the SetAntiAliasing function to avoid 25128 error does not work for me, I don’t think. I looked at mine and it was already uncommmented. But I am getting the error. I have standard GD installed (the one that came with PHP 5.3).
Also, I cannot find ” define(‘ANTIALIASING’, false); ” in jpg-config.cin.php.
Uncomment just one line in SetAntiAliasing:
function SetAntiAliasing($aFlg=true) { $this->use_anti_aliasing = $aFlg; if( function_exists('imageantialias') ) { imageantialias($this->img,$aFlg); } else { // JpGraphError::RaiseL(25128); // comment THIS line } }Thanks for the quick reply, I think there seems to be some confusion as to whether we are ‘commenting’ (removing) or ‘uncommenting’ (adding).
The guide above says to UNcomment the line, like I said, mine was already UNcommented. You above say to UNcomment the line, but in fact I need to ‘comment’ it out. i.e. make the program ignore that line of code.
Commenting the line OUT so it is not used, is what worked for me.
Secondly, How would I determine why the antialiasing is not working? I have a server running Ubuntu 10,04 with the latest PHP installed. It does not work with antialiasing.
I also have a Windows machine with Xampp Lite 1.7.3 running, where anti-aliasing DOES work… what would I need to do to make anti-aliasing work on my Linux box?
Cheers.
@Jon Reynolds: You are right, it was confusing in the text. I wrote “uncommenting” when I wanted to mean “commenting”. Thanks for pointing it out, I will correct that.
I don’t know how to activate antialiasing, but to tell the truth I didn’t look for a solution very hard either. This quick fix was fine for me.
No probs, got me confused for a bit :)
Thanks for the post anyway, saved a lot of headaches. Now to figure out why antialiasing is not working on my Linux server.
If you figure it out, leave a comment :)
This sorted me out here:
http://geertvandeweyer.zymichost.com/index.php?page=read&id=22
Hi,
thanks for the link :-)
The reason your antialias is not working is that the php-gd in ubuntu apt sources does not include the function. On the link above, there is a link to the page of Maxiwebs with *some* versions of php-gd with antialias support.
They are responsive, and will try to add more versions if you need a specific one.
wew thanks bro, for resolving error 52128,, :D
Wow, Now its working.
Thanks a lot…………….
commenting the anti aliasing worked for me tnx
After I commented that line also getting error — The image “URL” cannot be displayed because it contains errors.
Please suggest me how to fix this issue