1# Drawing a contour chart 2 3[Reference](http://wiki.pchart.net/doc.surface.drawcontour.html) 4 5```php 6require '/path/to/your/vendor/autoload.php'; 7 8use CpChart\Chart\Surface; 9use CpChart\Data; 10use CpChart\Image; 11 12/* Create the Image object */ 13$image = new Image(400, 400); 14 15/* Create a solid background */ 16$image->drawFilledRectangle(0, 0, 400, 400, [ 17 "R" => 179, 18 "G" => 217, 19 "B" => 91, 20 "Dash" => 1, 21 "DashR" => 199, 22 "DashG" => 237, 23 "DashB" => 111 24]); 25 26/* Do a gradient overlay */ 27$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [ 28 "StartR" => 194, 29 "StartG" => 231, 30 "StartB" => 44, 31 "EndR" => 43, 32 "EndG" => 107, 33 "EndB" => 58, 34 "Alpha" => 50 35]); 36$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [ 37 "StartR" => 0, 38 "StartG" => 0, 39 "StartB" => 0, 40 "EndR" => 50, 41 "EndG" => 50, 42 "EndB" => 50, 43 "Alpha" => 100 44]); 45 46/* Add a border to the picture */ 47$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]); 48 49/* Write the picture title */ 50$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 51$image->drawText(10, 13, "pSurface() :: 2D surface charts", ["R" => 255, "G" => 255, "B" => 255]); 52 53/* Define the charting area */ 54$image->setGraphArea(20, 40, 380, 380); 55$image->drawFilledRectangle(20, 40, 380, 380, [ 56 "R" => 255, 57 "G" => 255, 58 "B" => 255, 59 "Surrounding" => -200, 60 "Alpha" => 20 61]); 62 63$image->setShadow(true, ["X" => 1, "Y" => 1]); 64 65/* Create the surface object */ 66$surfaceChart = new Surface($image); 67 68/* Set the grid size */ 69$surfaceChart->setGrid(20, 20); 70 71/* Write the axis labels */ 72$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 73$surfaceChart->writeXLabels(["Position" => LABEL_POSITION_BOTTOM]); 74$surfaceChart->writeYLabels(); 75 76/* Add random values */ 77for ($i = 0; $i <= 50; $i++) { 78 $surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100)); 79} 80 81/* Compute the missing points */ 82$surfaceChart->computeMissing(); 83 84/* Draw the surface chart */ 85$surfaceChart->drawSurface(["Border" => true, "Surrounding" => 40]); 86 87/* Draw the contour with a threshold of 50 */ 88$surfaceChart->drawContour(50, ["R" => 0, "G" => 0, "B" => 0]); 89 90/* Render the picture (choose the best way) */ 91$image->autoOutput("example.surface.png"); 92``` 93