phpjpgraph

How to Change Theme On 3D Pie for JpChart


I can't get the theme or slice colors to change on a 3D pie chart. My code is:

$graph = new PieGraph(350,250);
$graph->SetShadow();

$graph->title->SetFont(FF_VERDANA,FS_BOLD,18); 
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.1,0.9);

// Create 3D pie plot
$p1 = new PiePlot3d($data);
$p1->SetLegends($legends);
$p1->SetTheme("earth");
$p1->SetCenter(0.4);
$p1->SetSize(100);
$p1->SetSliceColors(array("red","blue","yellow","orange"));

$p1->SetAngle(45);

$p1->value->SetFont(FF_ARIAL,FS_BOLD,8);
$p1->value->SetColor("navy");

$graph->Add($p1);

No matter what I do, the colors don't change. Am I missing something?


Solution

  • Add your plot to the graph before you change the theme and colors. If you think about it it makes perfect sense. You have to create (define/add) something before you can modify it.

    The changes shown below should work:

    // Create 3D pie plot
    $p1 = new PiePlot3d($data);
    
    $graph->Add($p1);  // moved adding the plot to the graph before changing other things
    
    $p1->SetLegends($legends);
    $p1->SetTheme("earth");
    $p1->SetCenter(0.4);
    $p1->SetSize(100);
    $p1->SetSliceColors(array("red","blue","yellow","orange"));
    $p1->SetAngle(45);
    $p1->value->SetFont(FF_ARIAL,FS_BOLD,8);
    $p1->value->SetColor("navy");