xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/3d_ring.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a 3D ring chart
2
3[Reference](http://wiki.pchart.net/doc.pie.draw3dring.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([50, 2, 3, 4, 7, 10, 25, 48, 41, 10], "ScoreA");
15$data->setSerieDescription("ScoreA", "Application A");
16
17/* Define the absissa serie */
18$data->addPoints(["A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"], "Labels");
19$data->setAbscissa("Labels");
20
21/* Create the Image object */
22$image = new Image(400, 400, $data);
23
24/* Draw a solid background */
25$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
26$image->drawFilledRectangle(0, 0, 400, 400, $settings);
27
28/* Overlay with a gradient */
29$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
30    "StartR" => 219,
31    "StartG" => 231,
32    "StartB" => 139,
33    "EndR" => 1,
34    "EndG" => 138,
35    "EndB" => 68,
36    "Alpha" => 50
37]);
38$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
39    "StartR" => 0,
40    "StartG" => 0,
41    "StartB" => 0,
42    "EndR" => 50,
43    "EndG" => 50,
44    "EndB" => 50,
45    "Alpha" => 100
46]);
47
48/* Add a border to the picture */
49$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
50
51/* Write the picture title */
52$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
53$image->drawText(10, 13, "pPie - Draw 3D ring charts", ["R" => 255, "G" => 255, "B" => 255]);
54
55/* Set the default font properties */
56$image->setFontProperties([
57    "FontName" => "Forgotte.ttf",
58    "FontSize" => 10,
59    "R" => 80,
60    "G" => 80,
61    "B" => 80
62]);
63
64/* Enable shadow computing */
65$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50]);
66
67/* Create the pPie object */
68$pieChart = new Pie($image, $data);
69
70/* Draw an AA pie chart */
71$pieChart->draw3DRing(200, 200, ["DrawLabels" => true, "LabelStacked" => true, "Border" => true]);
72
73/* Write the legend box */
74$pieChart->drawPieLegend(80, 360, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER, "Alpha" => 20]);
75
76/* Render the picture (choose the best way) */
77$image->autoOutput("example.draw3DRing.png");
78```
79