Reputation: 606
I used a JpGraph in php. Everything ok but slice ($p1->SetSliceColors($color);) color not work. It all time default color. Here is my used code. Please help me :
$data = array('40','50', '10');
$Legends = array('Loss','Win', 'Draw');
$labels = array("Loss\n(%.1f%%)","Win\n(%.1f%%)","Draw\n(%.1f%%)");
$color = array('red','red','red');
$graph = new PieGraph(550,350);
$graph->SetShadow();
$p1 = new PiePlot3D($data);
$p1->ExplodeSlice(1);
$p1->SetCenter(0.55);
$p1->SetLegends($Legends);
$graph->legend->Pos(0.5,0.1);
$p1->SetTheme("earth");
$p1->SetSliceColors($color);
// Setup the labels to be displayed
$p1->SetLabels($labels);
$p1->SetLabelPos(1);
$p1->SetLabelType(PIE_VALUE_PER);
$p1->value->Show();
$p1->value->SetFont(FF_FONT1,FS_NORMAL,9);
$p1->value->SetColor('navy');
$graph->Add($p1);
$graph->Stroke();
Upvotes: 5
Views: 7312
Reputation: 1352
Try call the SetSliceColors
method after you add the pie to the graph, and it would work as intended:
$data = array('40','50', '10');
$Legends = array('Loss','Win', 'Draw');
$labels = array("Loss\n(%.1f%%)","Win\n(%.1f%%)","Draw\n(%.1f%%)");
$color = array('red','red','red');
$graph = new PieGraph(550,350);
$graph->SetShadow();
$p1 = new PiePlot3D($data);
$p1->ExplodeSlice(1);
$p1->SetCenter(0.55);
$p1->SetLegends($Legends);
$graph->legend->Pos(0.5,0.1);
$p1->SetTheme("earth");
// Setup the labels to be displayed
$p1->SetLabels($labels);
$p1->SetLabelPos(1);
$p1->SetLabelType(PIE_VALUE_PER);
$p1->value->Show();
$p1->value->SetFont(FF_FONT1,FS_NORMAL,9);
$p1->value->SetColor('navy');
$graph->Add($p1);
$p1->SetSliceColors($color);
$graph->Stroke();
Upvotes: 0
Reputation: 1
You can use this line of code: Select the theme that you want to select, there are several options
$theme_class = new VividTheme;
$graph = new PieGraph(1000,300);//create the graph
$graph->ClearTheme();//clean
$graph->SetTheme($theme_class);//set the theme
Now you can see the result, you can see the different themes here:
https://jpgraph.net/download/manuals/chunkhtml/ch28.html
Other option is clean the theme, something like this
$graph = new PieGraph(1000,300);//create the graph
$graph->ClearTheme();//clean the theme
$colors = array('#336699', '#FF0000', '#00FF00', '#0000FF', '#FFFF00');//put color the colors that you want
$p1->SetSliceColors($colors);///set the colors
Upvotes: 0
Reputation: 131
I had the same problem. Call the Add method before setting colors:
$p1 = new PiePlot3D($data);
$graph->Add($p1);
Changing the display settings of line/bar graphs
Upvotes: 13
Reputation: 71
try
$graph = new PieGraph(550,350);
$graph->ClearTheme();
Leave out
$p1->SetTheme("earth");
SetSliceColors worked for me.
Upvotes: 5