xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/3d_pie.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a 3D pie chart
2
3[Reference](http://wiki.pchart.net/doc.pie.draw3dpie.html)
4
5```php
6require '/path/to/your/vendor/autoload.php';
7
8use CpChart\Chart\Pie;
9use CpChart\Data;
10use CpChart\Image;
11
12/* Create and populate the Data object */
13$data = new Data();
14$data->addPoints([40, 30, 20], "ScoreA");
15$data->setSerieDescription("ScoreA", "Application A");
16
17/* Define the absissa serie */
18$data->addPoints(["A", "B", "C"], "Labels");
19$data->setAbscissa("Labels");
20
21/* Create the Image object */
22$image = new Image(700, 230, $data, true);
23
24/* Draw a solid background */
25$image->drawFilledRectangle(0, 0, 700, 230, [
26    "R" => 173,
27    "G" => 152,
28    "B" => 217,
29    "Dash" => 1,
30    "DashR" => 193,
31    "DashG" => 172,
32    "DashB" => 237
33]);
34
35/* Draw a gradient overlay */
36$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, [
37    "StartR" => 209,
38    "StartG" => 150,
39    "StartB" => 231,
40    "EndR" => 111,
41    "EndG" => 3,
42    "EndB" => 138,
43    "Alpha" => 50
44]);
45$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
46    "StartR" => 0,
47    "StartG" => 0,
48    "StartB" => 0,
49    "EndR" => 50,
50    "EndG" => 50,
51    "EndB" => 50,
52    "Alpha" => 100
53]);
54
55/* Add a border to the picture */
56$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
57
58/* Write the picture title */
59$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
60$image->drawText(10, 13, "pPie - Draw 3D pie charts", ["R" => 255, "G" => 255,
61    "B" => 255]);
62
63/* Set the default font properties */
64$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10,
65    "R" => 80, "G" => 80, "B" => 80]);
66
67/* Create the pPie object */
68$pieChart = new Pie($image, $data);
69
70/* Define the slice color */
71$pieChart->setSliceColor(0, ["R" => 143, "G" => 197, "B" => 0]);
72$pieChart->setSliceColor(1, ["R" => 97, "G" => 77, "B" => 63]);
73$pieChart->setSliceColor(2, ["R" => 97, "G" => 113, "B" => 63]);
74
75/* Draw a simple pie chart */
76$pieChart->draw3DPie(120, 125, ["SecondPass" => false]);
77
78/* Draw an AA pie chart */
79$pieChart->draw3DPie(340, 125, ["DrawLabels" => true, "Border" => true]);
80
81/* Enable shadow computing */
82$image->setShadow(true, ["X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
83
84/* Draw a splitted pie chart */
85$pieChart->draw3DPie(560, 125, ["WriteValues" => true, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => true]);
86
87/* Write the legend */
88$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
89$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20]);
90$image->drawText(120, 200, "Single AA pass", [
91    "DrawBox" => true,
92    "BoxRounded" => true,
93    "R" => 0,
94    "G" => 0,
95    "B" => 0,
96    "Align" => TEXT_ALIGN_TOPMIDDLE
97]);
98$image->drawText(440, 200, "Extended AA pass / Splitted", [
99    "DrawBox" => true,
100    "BoxRounded" => true,
101    "R" => 0,
102    "G" => 0,
103    "B" => 0,
104    "Align" => TEXT_ALIGN_TOPMIDDLE
105]);
106
107/* Write the legend box */
108$image->setFontProperties([
109    "FontName" => "Silkscreen.ttf",
110    "FontSize" => 6,
111    "R" => 255,
112    "G" => 255,
113    "B" => 255
114]);
115$pieChart->drawPieLegend(600, 8, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
116
117/* Render the picture (choose the best way) */
118$image->autoOutput("example.draw3DPie.png");
119```
120