SourceForge.net  |  Sunyday.net
Last release: 1.27d
a PHP Class to build Charts
pChart 2.x is born, you can start moving your script to this new version. The new website is at www.pchart.net.
Overview  |  Screenshots  |  Download  |  Add-ons  |  Demonstration  |  Support  |  :: Documentation ::
Documentation Contents
Overview
Class definition
FAQ
Using pChart with MySQL
Playing with colors
Setting X labels
Series are drawn black?
Debugging charts
Call to undefined function
Digging with pChart
Basic Examples
Advanced Examples
Playing with colors

Finding the good colors to use in your graph is a tricky game. To help you dealing with color palettes we're providing some extended schemes that you can download clicking on the Add-ons link from this page top bar, then select color schemes. Basically pChart embed a 8 colors palette, this means that if you do not change the color settings, series with an ID greater than 8 will be shown as black. The pChart basic palette :

               
0
1
2
3
4
5
6
7

We'll show you here how to change one color or to bulk import a color scheme.

Changing the colors!

Let's first start by changing the existing palette. To do so the pChart class embed the setColorPalette() function. This function is taking 4 arguments, the first one is the color ID. What is important to understand here is that color ID start at 0 but series ID start at 1 : The color ID of the first serie 'Serie1' will be 0!

To change the color of the first serie to red :
setColorPalette(0,255,0,0);
To change the color of the third serie to blue :
setColorPalette(2,0,0,255);
Colors are defined using their R,G,B composantes. To understand this way of computing colors you can see this wikipedia article.

Loading a color scheme

If you don't want to write 10 times the setColorPalette() function you can load a color scheme from a flat text file. This is a flexible way to manage color palette as the same scheme can be reused from another pChart script. Modifying this scheme will also modify all script that are refering to it.

Basically a color scheme file is a text file with one R,G,B value per line. First line will be associated to the first data serie. R,G,B value can be separated with a coma or another separator of your choice.

To make soft green tones, create a file named 'palette.txt' containing :
168,188,56
188,208,76
208,228,96
228,245,116
248,255,136
         
0
1
2
3
4

..and load it using (assuming you pChart object is named $Test) :
$Test->loadColorPalette('palette.txt');
If you've choosen another delimiter than the coma, set this separator character as the second parameter of the loadColorPalette function call (here the delimiter will be the '¤' character) :
$Test->loadColorPalette('palette.txt','¤');
Now you can play with color palettes!

Last updated on 07/18/2008