RCHART for Php, User Guide
Copyright 2005, J4L
Components (http://www.java4less.com)
Go bak to contents
RChart , first steps.
Introduction
RChart for php is a script
that will create more than 18 different types of charts and combinations of
them:
- linechart
- barchart
- piechart
- bubblechart
- gaugechart
- radarchart
- columnchart
- OHLC
- Candlestick
- linechart 3D
- barchart 3D
- piechart 3D
- curves (3 different
types)
- scatterchart
- eventchart
- ...
The product can also create
image maps so you can add tips and html links to your charts. The image map
feature also allows you to create drill-down charts.
Furthermore the charts
support a large number of features:
- logarithmic scales.
- dates in scales.
- data population from
databases
- Any number of axis
- Target zones
- Label definition language
- configuration of all
fonts, lines and colors.
- images.
- second Y axis
- X axis on top
- exporting to png, jpg
or png
- ...
The charts can be created
in 2 ways:
- using parameters so
you do not have to worry about the api of the classes.This option requires
very little programming.
- using php code so you
can access all classes and properties. This option can be used for advanced
users and it is more flexible.
All examples in this tutorial
contain the list of parameters used and the equivalent php code.
Installation
RChart for Php requires
has the following requirements:
- A working PHP4 system
- GD library. It’s usually
bundled into PHP.
- FreeType Library, if
you want to use True Type fonts. Also bundled in recent PHP distributions.
- Support for specific
image formats such as GIF or JPEG if you want to use them. Default is PNG.
In recent PHP versions you will likely have at least PNG and JPEG
Installation:
- Configure your web server
to allow some directory to allocate a PHP application (make sure you can acces
this directory using an appropriate URL from your browser, make sure that
files with .php extension are parsed through the PHP interpreter, etc. )
- Uncompress the provided
distribution file into this directory. [ Advanced users: Alternatively you
can place it outside the web server tree. Then you may copy demonstration
files to the web accesible directory. In such case you should change the initial
include_path setting or configure otherwise the PHP include path to the distribution
“inc” directory, as it contains all necessary program files. ]
Where
to start
As starting point we recommend
you not to create a chart from scratch but to take one of the examples we provide
and start working by modifying them.
There is a file called
getChart.php which will allow you to create charts without any programming.
This file takes the chart parameters and creates the chart image. You can can
pass the chart parameters in 2 ways:
- as part of the request
(either GET or POST).
- as a separate file or
URL.
For example:
http://www.server.com/getChart.php?DATAFILE=data.txt
will read the chart parameters
from the file "data.txt". The parameters supported by getChart.php
are:
- DATAFILE. Local file
or url where the chart parameters are to be found.
- WIDTH, HEIGHT: size
of the chart
- TYPE: type of image:
png (default), gif or jpg.
- OUTPUT: type of output:
image (default) or imagemap (use to create a html image map).
- MAPNAME: name of the
image map to create (only used if OUTPUT=imagemap).
Tip: take one of
our examples (barchart.txt) , copy it to your server and try it:
http://www.server.com/getChart.php?DATAFILE=http://www.server.com/barchart.txt
Format
of the parameters
There are some parameters
that have a special format:
- Colors: valid
values are:
RED
WHITE
GREEN
BLUE
YELLOW
GRAY
DARKGRAY
BLACK
LIME
OLIVE
MAROON
NAVY
PURPLE
TELA
FUCHSIA
AQUA
ALICEBLUE
ANTIQUEWHITE
AQUAMARINE
AZURE
BEIGE
BLUEVIOLET
BROWN
BORLYWOOD
CORAL
CYAN
DARKGOLDENROD
DARKGREEN
DARKOLIVEGREEN
DARKORANGE
DARKORCHID
DARKSALMON
DARKTURQUOISE
DARKVIOLET
DEEPPINK
DEEPSKYBLUE
FORESTGREEN
GOLD
GOLDENROD
GREENYELLOW
HOTPINK
INDIANRED
IVORY
LAVENDER
LAWNGREEN
LIGHTBLUE
LIGHTCORAL
LIGHTCYAN
LIGHTGRAY
LIGHTPINK
LIGHTSALMON
LIGHTSKYBLUE
LIGHTYELLO
LIMEGREEN
MAGENTA
MEDIUMBLUE
MEDIUMPURPLE
MIDNIGHTBLUE
ORANGE
ORANGERED
ORCHID
PALEGREEN
PALETURQUOISE
PALEVIOLETRED
PINK
PLUM
PURPLE
SALMON
SEAGREEN
SIENNA
SKYBLUE
SPRINGGREEN
TURQUOISE
VIOLET
YELLOWGREEN
You can also use the comma separated RGB value of a color as parameter. For
example #FF00FF is red (RGB format).
You can define transparent
colors in the following way (PHP 4 >= 4.3.2 only ):
<color number>|<transparency>
where <transparency> is a value between 127 (full transparent) and
0(opaque). You can use 60 for semi-transparent colors.
for example:
#FF0000|60
- Line styles have
the format <width>|<color>|<style>. Style can be LINE, DASHED
or DOTS. Example: "1|RED|LINE"
- Fonts have the
format <font name>|<size>. If you use one of the built-in fonts:
Default-1, Default-2 to Default-5, you do not have to specify the size. You
can also use TTF fonts, the files must be located in the "c:/windows/fonts"
or "./fonts" directory. Examples:
FONT=Default-1
FONT=arial|10
FONT=/myfonts/arial.ttf|10
- Fill style: there
are several options:
- <color>: for
plain color filling.
- <color>|<transparentcy>:
for transparent color filling. <transparency> is a value between
127(full transparent) and 0(opaque).
- <colorFrom>:<colorTo>:<orientation>:
for gradient filling. <orientation> can be VERTICAL or HORIZONTAL.
The fill style of following bar has been defined with "RED:ORANGE:HORIZONTAL".
as you can see the color changes from the <colorFrom> to the <colorTo>.
Gradients can be used for bars only, not for areacharts.
- <imageFile>.
For pattern filling. The following area chart uses a pattern filling defined
as "pattern1.gif"
- List of values.
List of values a separated by "|" , only certain parameters like
FiIll styles use another separator.