1# Drawing a polar chart 2 3[Reference](http://wiki.pchart.net/doc.draw.polar.html) 4 5```php 6require '/path/to/your/vendor/autoload.php'; 7 8use CpChart\Chart\Radar; 9use CpChart\Data; 10use CpChart\Image; 11 12/* Create and populate the Data object */ 13$data = new Data(); 14$data->addPoints([10, 20, 30, 40, 50, 60, 70, 80, 90], "ScoreA"); 15$data->addPoints([20, 40, 50, 12, 10, 30, 40, 50, 60], "ScoreB"); 16$data->setSerieDescription("ScoreA", "Coverage A"); 17$data->setSerieDescription("ScoreB", "Coverage B"); 18 19/* Define the absissa serie */ 20$data->addPoints([40, 80, 120, 160, 200, 240, 280, 320, 360], "Coord"); 21$data->setAbscissa("Coord"); 22 23/* Create the Image object */ 24$image = new Image(700, 230, $data); 25 26/* Draw a solid background */ 27$settings = ["R" => 179, "G" => 217, "B" => 91, "Dash" => 1, "DashR" => 199, "DashG" => 237, "DashB" => 111]; 28$image->drawFilledRectangle(0, 0, 700, 230, $settings); 29 30/* Overlay some gradient areas */ 31$settings = ["StartR" => 194, "StartG" => 231, "StartB" => 44, "EndR" => 43, "EndG" => 107, "EndB" => 58, "Alpha" => 50]; 32$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings); 33$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [ 34 "StartR" => 0, 35 "StartG" => 0, 36 "StartB" => 0, 37 "EndR" => 50, 38 "EndG" => 50, 39 "EndB" => 50, 40 "Alpha" => 100 41]); 42 43/* Add a border to the picture */ 44$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]); 45 46/* Write the picture title */ 47$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 48$image->drawText(10, 13, "pRadar - Draw polar charts", ["R" => 255, "G" => 255, 49 "B" => 255]); 50 51/* Set the default font properties */ 52$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 10, 53 "R" => 80, "G" => 80, "B" => 80]); 54 55/* Enable shadow computing */ 56$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, 57 "Alpha" => 10]); 58 59/* Create the pRadar object */ 60$radarChart = new Radar(); 61 62/* Draw a polar chart */ 63$image->setGraphArea(10, 25, 340, 225); 64$options = ["BackgroundGradient" => [ 65 "StartR" => 255, 66 "StartG" => 255, 67 "StartB" => 255, 68 "StartAlpha" => 100, 69 "EndR" => 207, 70 "EndG" => 227, 71 "EndB" => 125, 72 "EndAlpha" => 50 73]]; 74$radarChart->drawPolar($image, $data, $options); 75 76/* Draw a polar chart */ 77$image->setGraphArea(350, 25, 690, 225); 78$options = [ 79 "LabelPos" => RADAR_LABELS_HORIZONTAL, 80 "BackgroundGradient" => [ 81 "StartR" => 255, "StartG" => 255, "StartB" => 255, "StartAlpha" => 50, "EndR" => 32, 82 "EndG" => 109, "EndB" => 174, "EndAlpha" => 30 83 ], 84 "AxisRotation" => 0, 85 "DrawPoly" => true, 86 "PolyAlpha" => 50 87]; 88$radarChart->drawPolar($image, $data, $options); 89 90/* Write the chart legend */ 91$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 92$image->drawLegend(270, 205, ["Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL]); 93 94/* Render the picture (choose the best way) */ 95$image->autoOutput("example.polar.png"); 96``` 97