xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/zone.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a zone chart
2
3[Reference](http://wiki.pchart.net/doc.chart.drawzonechart.html)
4
5```php
6require '/path/to/your/vendor/autoload.php';
7
8use CpChart\Data;
9use CpChart\Image;
10
11/* Create and populate the Data object */
12$data = new Data();
13for ($i = 0; $i <= 10; $i = $i + .2) {
14    $data->addPoints(log($i + 1) * 10, "Bounds 1");
15    $data->addPoints(log($i + 3) * 10 + rand(0, 2) - 1, "Probe");
16    $data->addPoints(log($i + 6) * 10, "Bounds 2");
17    $data->addPoints($i * 10, "Labels");
18}
19$data->setAxisName(0, "Size (cm)");
20$data->setSerieDescription("Labels", "Months");
21$data->setAbscissa("Labels");
22$data->setAbscissaName("Time (years)");
23
24/* Create the Image object */
25$image = new Image(700, 230, $data);
26
27/* Turn off Antialiasing */
28$image->Antialias = false;
29
30/* Add a border to the picture */
31$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
32
33/* Write the chart title */
34$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]);
35$image->drawText(150, 35, "Size by time generations", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]);
36
37/* Set the default font */
38$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
39
40/* Define the chart area */
41$image->setGraphArea(40, 40, 680, 200);
42
43/* Draw the scale */
44$image->drawScale([
45    "LabelSkip" => 4,
46    "XMargin" => 10,
47    "YMargin" => 10,
48    "Floating" => true,
49    "GridR" => 200,
50    "GridG" => 200,
51    "GridB" => 200,
52    "DrawSubTicks" => true,
53    "CycleBackground" => true
54]);
55
56/* Turn on Antialiasing */
57$image->Antialias = true;
58
59/* Draw the line chart */
60$image->drawZoneChart("Bounds 1", "Bounds 2");
61$data->setSerieDrawable(["Bounds 1", "Bounds 2"], false);
62
63/* Draw the line chart */
64$image->drawStepChart();
65
66/* Write the chart legend */
67$image->drawLegend(640, 20, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
68
69/* Render the picture (choose the best way) */
70$image->autoOutput("example.drawZoneChart.png");
71```
72