Home > php > Drawing graphs in PHP with JpGraph

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.


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:


# 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.


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.

Categories: php Tags: , , , ,
  1. omar
    February 15, 2011 at 07:15

    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.

  2. omar
    February 15, 2011 at 07:20

    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.’)

  3. Marco
    September 13, 2011 at 10:00

    Thanks a lot!!

  4. October 26, 2011 at 15:16


  5. Guillaume
    November 18, 2011 at 13:50

    To fix the issue. Just overwrite the function imageantialias
    In jpg-config.inc.php :

    define('ANTIALIASING', false);
    	function imageantialias($image, $enabled)
    		return true;
    • Joerx
      March 5, 2012 at 08:12

      Definitely better then writing directly into 3rd party libs core classes. Even better: function_exists(‘imageantialias’) so no need to manually set a constant.

      • July 31, 2012 at 11:23

        Combined the solutions of Guillaume and Joerx:

            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.

  6. November 22, 2011 at 12:01

    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.

    • November 22, 2011 at 12:54

      Uncomment just one line in SetAntiAliasing:

      function SetAntiAliasing($aFlg=true) {
          $this->use_anti_aliasing = $aFlg;
          if( function_exists('imageantialias') ) { 
          else {
              // JpGraphError::RaiseL(25128); // comment THIS line
      • November 22, 2011 at 13:31

        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?


  7. November 22, 2011 at 13:54

    @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.

    • November 22, 2011 at 14:17

      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.

      • November 22, 2011 at 14:19

        If you figure it out, leave a comment :)

  8. November 22, 2011 at 14:29
    • December 1, 2011 at 22:21


      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.

  9. April 7, 2012 at 03:30

    wew thanks bro, for resolving error 52128,, :D

  10. jithin.k.k
    May 1, 2012 at 08:37

    Wow, Now its working.
    Thanks a lot…………….

  11. Jixa
    August 13, 2012 at 13:54

    commenting the anti aliasing worked for me tnx

  12. March 8, 2013 at 08:50

    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

    • July 4, 2016 at 08:01

      This can be caused by extra whitespace on the page. Make sure you don’t have any spaces or line breaks before your opening <?php tag.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: