I am developing php pie chats with pChart, it looks nice. Now I want to change color of each slices. Is it possible to change the color?
Asked
Active
Viewed 2,787 times
3 Answers
2
The function you are looking for is setSliceColor() - http://wiki.pchart.net/doc.pie.setslicecolor.html
Assuming you have created a new pie chart from some data:
$PieChart = new pPie($myPicture,$MyData);
You can then use it like this:
$PieChart->setSliceColor(0, array("R" => 255, "G" => 0, "B" => 0));
$PieChart->setSliceColor(1, array("R" => 0, "G" => 255, "B" => 0));
etc...

Tom
- 688
- 13
- 29
-
This is the correct way to do it, at least for pChart 2.0. Remember to do this BEFORE you call ->draw2DPie or whatever draw command you want to do. – Richard Apr 04 '14 at 15:14
1
For pChart (almost all versions), you will just use this :
...
$PieChart = new pPie($myPicture,$MyData);
$PieChart->setSliceColor(0,array("R"=>255,"G"=>128,"B"=>0));
$PieChart->setSliceColor(1,array("R"=>255,"G"=>255,"B"=>255));
$PieChart->setSliceColor(2,array("R"=>25,"G"=>128,"B"=>0));
$PieChart->setSliceColor(3,array("R"=>55,"G"=>255,"B"=>25));
...
Just add more setSliceColor for more slice on your chart

pollux1er
- 5,372
- 5
- 37
- 36
0
I solved this question just doing this:
/*
Example 10 - A 3D exploded pie graph
Version 1.27d pChart*/
$Test->loadColorPalette('ColorsDirectory/tones-9.txt',',');
$Test->drawPieGraph(
$DataSet->GetData(),
$DataSet->GetDataDescription(),
350,130,110,PIE_PERCENTAGE_LABEL,FALSE,50,20,5);
...
Call loadColorPalette just before calling drawPieGraph. It works this way.Good luck!

Mark Lakata
- 19,989
- 5
- 106
- 123