xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/scatter_threshold.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a scatter threshold chart
2
3[Reference](http://wiki.pchart.net/doc.scatter.drawscatterthreshold.html)
4
5```php
6require '/path/to/your/vendor/autoload.php';
7
8use CpChart\Chart\Scatter;
9use CpChart\Data;
10use CpChart\Image;
11
12/* Create the Data object */
13$data = new Data();
14
15/* Create the X axis and the binded series */
16$data->createFunctionSerie("X", "1/z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
17$data->setAxisName(0, "x = 1/z");
18$data->setAxisXY(0, AXIS_X);
19$data->setAxisPosition(0, AXIS_POSITION_BOTTOM);
20
21/* Create the Y axis */
22$data->createFunctionSerie("Y", "z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
23$data->setSerieOnAxis("Y", 1);
24$data->setAxisName(1, "y = z");
25$data->setAxisXY(1, AXIS_Y);
26$data->setAxisPosition(1, AXIS_POSITION_RIGHT);
27
28/* Create the Y axis */
29$data->createFunctionSerie("Y2", "z*z*z", ["MinX" => -10, "MaxX" => 10, "XStep" => 1]);
30$data->setSerieOnAxis("Y2", 2);
31$data->setAxisName(2, "y = z*z*z");
32$data->setAxisXY(2, AXIS_Y);
33$data->setAxisPosition(2, AXIS_POSITION_LEFT);
34
35/* Create the 1st scatter chart binding */
36$data->setScatterSerie("X", "Y", 0);
37$data->setScatterSerieDescription(0, "Pass A");
38$data->setScatterSerieTicks(0, 4);
39$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]);
40
41/* Create the 2nd scatter chart binding */
42$data->setScatterSerie("X", "Y2", 1);
43$data->setScatterSerieDescription(1, "Pass B");
44$data->setScatterSerieTicks(1, 4);
45$data->setScatterSerieColor(1, ["R" => 120, "G" => 0, "B" => 255]);
46
47/* Create the Image object */
48$image = new Image(400, 400, $data);
49
50/* Draw the background */
51$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
52$image->drawFilledRectangle(0, 0, 400, 400, $settings);
53
54/* Overlay with a gradient */
55$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [
56    "StartR" => 219,
57    "StartG" => 231,
58    "StartB" => 139,
59    "EndR" => 1,
60    "EndG" => 138,
61    "EndB" => 68,
62    "Alpha" => 50
63]);
64$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [
65    "StartR" => 0,
66    "StartG" => 0,
67    "StartB" => 0,
68    "EndR" => 50,
69    "EndG" => 50,
70    "EndB" => 50,
71    "Alpha" => 80
72]);
73
74/* Write the picture title */
75$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
76$image->drawText(10, 13, "createFunctionSerie() - Functions computing", [
77    "R" => 255,
78    "G" => 255,
79    "B" => 255
80]);
81
82/* Add a border to the picture */
83$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]);
84
85/* Set the default font */
86$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
87
88/* Set the graph area */
89$image->setGraphArea(50, 50, 350, 350);
90
91/* Create the Scatter chart object */
92$myScatter = new Scatter($image, $data);
93
94/* Draw the scale */
95$myScatter->drawScatterScale(["XMargin" => 10, "YMargin" => 10, "Floating" => true]);
96
97/* Turn on shadow computing */
98$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
99
100/* Draw the 0/0 lines */
101$myScatter->drawScatterThreshold(0, ["AxisID" => 0, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 10]);
102$myScatter->drawScatterThreshold(0, ["AxisID" => 1, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 10]);
103
104/* Draw a treshold area */
105$myScatter->drawScatterThresholdArea(-0.1, 0.1, ["AreaName" => "Error zone"]);
106
107/* Draw a scatter plot chart */
108$myScatter->drawScatterLineChart();
109$myScatter->drawScatterPlotChart();
110
111/* Draw the legend */
112$myScatter->drawScatterLegend(300, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]);
113
114/* Render the picture (choose the best way) */
115$image->autoOutput("example.createFunctionSerie.scatter.png");
116```
117