1# Drawing a surface chart 2 3[Reference](http://wiki.pchart.net/doc.surface.drawsurface.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$settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111]; 17$image->drawFilledRectangle(0, 0, 400, 400, $settings); 18 19$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, [ 20 "StartR" => 194, 21 "StartG" => 231, 22 "StartB" => 44, 23 "EndR" => 43, 24 "EndG" => 107, 25 "EndB" => 58, 26 "Alpha" => 50 27]); 28$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [ 29 "StartR" => 0, 30 "StartG" => 0, 31 "StartB" => 0, 32 "EndR" => 50, 33 "EndG" => 50, 34 "EndB" => 50, 35 "Alpha" => 100 36]); 37 38/* Add a border to the picture */ 39$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]); 40 41/* Write the picture title */ 42$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 43$image->drawText(10, 13, "pSurface() :: 2D surface charts", ["R" => 255, "G" => 255, "B" => 255]); 44 45/* Define the charting area */ 46$image->setGraphArea(20, 40, 380, 380); 47$image->drawFilledRectangle(20, 40, 380, 380, [ 48 "R" => 255, 49 "G" => 255, 50 "B" => 255, 51 "Surrounding" => -200, 52 "Alpha" => 20 53]); 54 55$image->setShadow(true, ["X" => 1, "Y" => 1]); 56 57/* Create the surface object */ 58$surfaceChart = new Surface($image); 59 60/* Set the grid size */ 61$surfaceChart->setGrid(20, 20); 62 63/* Write the axis labels */ 64$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 65$surfaceChart->writeXLabels(); 66$surfaceChart->writeYLabels(); 67 68/* Add random values */ 69for ($i = 0; $i <= 50; $i++) { 70 $surfaceChart->addPoint(rand(0, 20), rand(0, 20), rand(0, 100)); 71} 72 73/* Compute the missing points */ 74$surfaceChart->computeMissing(); 75 76/* Draw the surface chart */ 77$surfaceChart->drawSurface(["Border" => true, "Surrounding" => 40]); 78 79/* Render the picture (choose the best way) */ 80$image->autoOutput("example.surface.png"); 81``` 82