1 3D Capabilities in JpGraph
1.1 3D Pie plots
3D pie
plots is treated in much the same way as normal pie plots. 3D pie plots are created
as instances of Class PiePlot3D instead of the usual Class PiePlot.
Figure 61. A simple example of 3D pie plot
Let’s first note a few things
The essential part of the code for the image in Figure 61 is shown below
<?php
include ("../jpgraph.php");
include ("../jpgraph_pie.php");
include ("../jpgraph_pie3d.php");
// Some data
$data = array(20,17,15,20,15,25,25,10);
// Create the Pie Graph.
$graph = new PieGraph(350,200,"pieex1");
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set("Example 1 3D Pie plot");
$graph->title->SetFont(FF_VERDANA,FS_BOLD,18);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.1,0.2);
// Create 3D pie plot
$p1 = new PiePlot3d($data);
$p1->SetTheme("sand");
$p1->SetCenter(0.4);
$p1->SetAngle(50);
$p1->SetFont(FF_TIMES,FS_NORMAL,14);
$p1->SetLegends(array("Jan","Feb","Mar","Apr", "May","Jun","Jul","Aug","Sep","Oct"));
$graph->Add($p1);
$graph->Stroke();
?>
Figure 62. Example of code for 3D pie graph.
From this example you can see that the 3D part of the pie is really an extension to the usual pie so that you need to include the 3 files
include ("../jpgraph.php");
include ("../jpgraph_pie.php");
include ("../jpgraph_pie3d.php");
whenever you would like to use a 3D pie plot. To illustrate the difference perspective lets tilt the pie back to 30 degrees by calling SetAngle(30) (the minimum allowed angle) the resulting figure will then look like shown in Figure 63.
Figure 63. Example of pie plot with 30 degrees projection angle.
You might also want to note that in the same way as for normal pie plots 3D plots uses color themes to specify a set of colors for the slices. In the example above we used the theme “sand”.
[1] The reason for this limit is basically to avoid some potential problem with color filling on the edges due to the way the 3D ellipses are constructed. To relieve this restriction would require serious addition to the complexity of the existing code and simply speaking, it isn’t worth it.