Contents
Previous
Next
In general the only thing you need to do is to make sure your PHP files
can include the required library files (as described below) and that
your PHP installation supports at least one graphic format, i.e. it
supports the "image" extension to PHP.
You can easily verify this by making sure that your installation of
PHP supports some of the 'imagecreate()' functions.
This means that you
must have a working GD-library together with PHP
before even thinking of running JpGraph. Please make sure you have
version 4.1 or above of PHP since JpGraph is not
tested with versions prior to PHP 4.1. Ideally you should use at least
PHP 4.3.x
If you want to use TTF fonts you must also make sure that your PHP
installation supports TTF fonts (either through FreeType 1 or FreeType
2 libraries). In additions to this you need at least a couple of TTF
fonts. In preparation of using TTF fonts with JpGRaph you must specify,
in jpgraph.php , where those font files can be found.
JpGraph uses a naming convention for the TTF font files in order to
be able to find the correct font files. You should therefore use the
font files that can be downloaded together with JpGraph.
In order to make sure that you have GD installed you could try by
running the following example which creates a very simple image using
just pure GD calls and outputs an image in PNG format.
header ("Content-type: image/png");
$im = @ImageCreate (50, 100)
or die ("Cannot create a new GD image.");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
ImageString ($im, 1, 5, 5, "A Simple Text String", $text_color);
ImagePng ($im);
The above script must work before you will have any
chance of getting JpGraph working.
In addition to European font it is also possible to use non-latin based
fonts such as Cyrillic, Japanes and Chinese.
In all cases you must have a suitable TTF font that supports the
non-latin based language you want to use.
For Cyrillic support you need to set the define LANGUAGE_CYRILLIC in
jpgraph.php to true. You can then use a suitable Cyrillic font as
replacement for the ordinary fonts.
For Chinese JpGraph supports both BIG5 and gb2312 encoding. For BIG5
encoding your PHP installation must have support for the "iconv()"
function. Furthermore you need to set the define CHINESE_TTF_FONT to
the name of the Chinese BIG5 font you want to use. By default this is
set to "bkai00mp.ttf". To use the Chinese BIG5 font for your texts you
need to sepcify the font family as FF_CHINESE.
If you instead want to use the simsun.ttc of simhei.ttf fonts which
use the gb2312 encoding you only need to install those fonts in the
normal TTF font directory and then specify the font family as FF_SIMSUN
(the simhei.ttf is used when you specify the fonts style as FS_BOLD.
In order for JpGraph to work you must adjust the cache and TTF
directory to suit your installation. By default the TTF directory is
"/usr/local/fonts/ttf/" and for the cache "/tmp/jpgraph_cache/". These
are defined as PHP defines at the top of jpgraph.php
Please make sure that PHP has write permissions to the cache
directory if you plan to use the cache feature. If not you will get a
"Can't write file xxx.yyy" error when you try to genereate a graph. You
can read more about how to use the cache in the chapter
Making sense of caching system in JpGraph
This is the base library files, which you must have
- Jpgraph.php, base library, always needed
To add plots to the graph you will need one or more of the following
files plot extension files dependiong on what kind of graph you need to
create.
- jpgraph_log.php, Plot extension to support logarithmic X and Y
scales
- jpgraph_line.php, Plot extension. Needed to draw various line plots
- jpgraph_bar.php, Plot extension. Needed to draw various bar plots
- jpgraph_error.php, Plot extension. Needed to draw various error
plots
- jpgraph_scatter.php, Plot extension. Needed to draw scatter and
impuls plots.
- jpgraph_spider.php, Plot extension. Needed to draw spider plots.
- jpgraph_pie.php, Plot extension. Needed to draw Pie plots
- jpgraph_pie3d.php, Plot extension. Needed to draw 3D Pie plots
- jpgraph_gantt.php, Plot extension. Needed to create gantt plots
- jpgraph_radar.php, Plot extension. Needed for radar plots
- jpgraph_polar.php, Plot extenion. Needed for Polar plots
- jpgraph_gantt.php, Plot extension. Needed for Gantt charts
- jpgraph_regstat.php, Statistic extension. Needed to plot spline
curves
- jpgraph_stock.php, Plot extension. Needed to plot stock charts
- jpgraph_gradient.php, Internal module. Contains all color gradient
- jpgraph_gb2312.php, Handling of gb2312 font encoding (used for some
chinese fonts)
- jpgraph_plotmark.php, Handling of plotmarks in line and scatter
plot.
- jpgraph_flags.php, Handling of country flags used as plot marks or
as backgrounds.
- imgdata_*.inc, Encoded images for plotmarks
- flags*.dat, Image data for flags. Pre-compiled data for country
flags.
- jpgraph_canvas.php, Plot extension to make it possible to draw
arbitrary graphic on a canvas.
- jpgraph_canvtools.php, Add on to the canvas graph to privide an
easier way to rdaw arbitrary shapes.
Per default the standard GD image library supports PNG graphic formats.
You will need to have that installed together with your PHP module for
this library to work at all. Please refer to PHP documentation on
specifics. Note that the newer versions of GD does not support the GIF
format due to copyright problems. Hence by default only PNG is
supported.
If you want JPEG support you will also need an additional library
for PHP, again please see PHP documentation for specifics. For most
practical purposes PNG is a better format since it normally achieves
better compression then GIF (typically by a factor of 2 for the types
of images generated by JpGraph). In comparison with JPEG format PNG is
also better for the type of images generated by this library. So, the
bottom line is, you should have a very good reason to choose any other
format then PNG.
By default the image format is set to "auto". This means that
JpGraph automatically chooses the best available graphic using the
preferred order "PNG", "GIF", "JPG".
- Make sure your PHP is AT LEAST 4.1 (preferrable 4.3.1 >= 1) and that
you have compiled support for GD library. You must make aboslutely sure
that you have GD working. Please run phpinfo() to check if GD library
is supported in your installation. JpGraph supports both GD 1.x and GD
2.x However it is strongly recommended to use GD 2.x since that will
improve performance and support truecolor images.
- Unzip and copy the files to a directory of your choice.
- Set up the directory paths in jpgraph.php where the cache directory
should be and where your TTF directory is. Note that Apache/PHP must
have write permission in your cache directory.
- Check that all rest of the DEFINE in the top of JpGraph.php is
setup to your preference. The default should be fine for most users.
(See also Note 5. below) Specifically check that the settings of
USE_GD2_LIBRARY reflects your installation, (should be true if you have
GD2 installed, false otherwise).
- Make sure PHP have write privileges to your cache directory if you
plan on using the cache feature.
- Some windows installations seems to have a problem with a PHP
script ending in a newline (This newline seems to be sent to the
browser and will cause a Header already sent error). If you have this
problem try remove all trailing newlines in the jpgraph* files
- Read (really!)
the JpGraph FAQ.
- If you don't get any background images (but rather a solid black
box) you are using GD 2.x but have forgotten to enable truecolor
support. Correct this by enabling the USE_TRUECOLOR define.
- If background images does not work make sure the settings of
USE_GD2_LIBRARY corresponds to your installation, i.e. If you don't
have GD2 then this define must be false!
- If you are running IIS and Win2k and get the error "Can't find
font" when trying to use TTF fonts then try to change you paths to UNIX
style, i.e. "/usr/local/fonts/ttf/". Remember that the path is absolute
and not relative to the htdocs catalogue.
- If you are using the cache please make sure that you have set the
permissions correctly for the cache directory so that Apache/PHP can
write to that directory.
Contents
Previous
Next