xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/split_path.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a split path chart
2
3[Reference](http://wiki.pchart.net/doc.chart.drawsplitpath.html)
4
5```php
6require '/path/to/your/vendor/autoload.php';
7
8use CpChart\Data;
9use CpChart\Image;
10use CpChart\Chart\Split;
11
12/* Create the Image object */
13$data = new Image(700, 230);
14
15/* Draw the background */
16$settings = [
17    "R" => 170,
18    "G" => 183,
19    "B" => 87,
20    "Dash" => 1,
21    "DashR" => 190,
22    "DashG" => 203,
23    "DashB" => 107
24];
25$data->drawFilledRectangle(0, 0, 700, 230, $settings);
26
27/* Overlay with a gradient */
28$settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1,
29    "EndG" => 138, "EndB" => 68, "Alpha" => 50];
30$data->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
31$data->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0,
32    "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
33
34/* Add a border to the picture */
35$data->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
36
37/* Write the picture title */
38$data->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
39$data->drawText(10, 13, "pSplit - Draw splitted path charts", ["R" => 255, "G" => 255, "B" => 255]);
40
41/* Set the default font properties */
42$data->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80]);
43
44/* Enable shadow computing */
45$data->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
46
47/* Create and populate the Data object */
48$data = new Data();
49$data->addPoints([30, 20, 15, 10, 8, 4], "Score");
50$data->addPoints(["End of visit", "Home Page", "Product Page", "Sales", "Statistics", "Prints"], "Labels");
51$data->setAbscissa("Labels");
52
53/* Create the pSplit object */
54$splitChart = new Split();
55
56/* Draw the split chart */
57$settings = ["TextPos" => TEXT_POS_RIGHT, "TextPadding" => 10, "Spacing" => 20, "Surrounding" => 40];
58$data->setGraphArea(10, 20, 340, 230);
59$splitChart->drawSplitPath($data, $data, $settings);
60
61/* Create and populate the Data object */
62$data2 = new Data();
63$data2->addPoints([30, 20, 15], "Score");
64$data2->addPoints(["UK", "FR", "ES"], "Labels");
65$data2->setAbscissa("Labels");
66
67/* Draw the split chart */
68$settings = ["TextPadding" => 4, "Spacing" => 30, "Surrounding" => 20];
69$data->setGraphArea(350, 50, 690, 200);
70$splitChart->drawSplitPath($data, $data2, $settings);
71
72/* Render the picture (choose the best way) */
73$data->autoOutput("example.split.png");
74```
75