xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/2d_ring.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a 2D ring chart
2
3[Reference](http://wiki.pchart.net/doc.pie.draw2dring.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(300, 260, $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, 300, 300, $settings);
27
28/* Overlay with a gradient */
29$image->drawGradientArea(0, 0, 300, 260, 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, 300, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0,
39    "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
40
41/* Add a border to the picture */
42$image->drawRectangle(0, 0, 299, 259, ["R" => 0, "G" => 0, "B" => 0]);
43
44/* Write the picture title */
45$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
46$image->drawText(10, 13, "pPie - Draw 2D ring charts", ["R" => 255, "G" => 255, "B" => 255]);
47
48/* Set the default font properties */
49$image->setFontProperties([
50    "FontName" => "Forgotte.ttf",
51    "FontSize" => 10,
52    "R" => 80,
53    "G" => 80,
54    "B" => 80
55]);
56
57/* Enable shadow computing */
58$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50]);
59
60/* Create the pPie object */
61$pieChart = new Pie($image, $data);
62
63/* Draw an AA pie chart */
64$pieChart->draw2DRing(160, 140, ["DrawLabels" => true, "LabelStacked" => true, "Border" => true]);
65
66/* Write the legend box */
67$image->setShadow(false);
68$pieChart->drawPieLegend(15, 40, ["Alpha" => 20]);
69
70/* Render the picture (choose the best way) */
71$image->autoOutput("example.draw2DRing.png");
72```
73