1# Drawing a scatter line chart 2 3[Reference](http://wiki.pchart.net/doc.scatter.drawscatterlineChart.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 */ 16for ($i = 0; $i <= 360; $i = $i + 10) { 17 $data->addPoints(cos(deg2rad($i)) * 20, "Probe 1"); 18} 19for ($i = 0; $i <= 360; $i = $i + 10) { 20 $data->addPoints(sin(deg2rad($i)) * 20, "Probe 2"); 21} 22$data->setAxisName(0, "Index"); 23$data->setAxisXY(0, AXIS_X); 24$data->setAxisPosition(0, AXIS_POSITION_BOTTOM); 25 26/* Create the Y axis and the binded series */ 27for ($i = 0; $i <= 360; $i = $i + 10) { 28 $data->addPoints($i, "Probe 3"); 29} 30$data->setSerieOnAxis("Probe 3", 1); 31$data->setAxisName(1, "Degree"); 32$data->setAxisXY(1, AXIS_Y); 33$data->setAxisUnit(1, "°"); 34$data->setAxisPosition(1, AXIS_POSITION_RIGHT); 35 36/* Create the 1st scatter chart binding */ 37$data->setScatterSerie("Probe 1", "Probe 3", 0); 38$data->setScatterSerieDescription(0, "This year"); 39$data->setScatterSerieTicks(0, 4); 40$data->setScatterSerieColor(0, ["R" => 0, "G" => 0, "B" => 0]); 41 42/* Create the 2nd scatter chart binding */ 43$data->setScatterSerie("Probe 2", "Probe 3", 1); 44$data->setScatterSerieDescription(1, "Last Year"); 45 46/* Create the Image object */ 47$image = new Image(400, 400, $data); 48 49/* Draw the background */ 50$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107]; 51$image->drawFilledRectangle(0, 0, 400, 400, $settings); 52 53/* Overlay with a gradient */ 54$settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50]; 55$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings); 56$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [ 57 "StartR" => 0, 58 "StartG" => 0, 59 "StartB" => 0, 60 "EndR" => 50, 61 "EndG" => 50, 62 "EndB" => 50, 63 "Alpha" => 80 64]); 65 66/* Write the picture title */ 67$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 68$image->drawText(10, 13, "drawScatterLineChart() - Draw a scatter line chart", [ 69 "R" => 255, 70 "G" => 255, 71 "B" => 255 72]); 73 74/* Add a border to the picture */ 75$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]); 76 77/* Set the default font */ 78$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 79 80/* Set the graph area */ 81$image->setGraphArea(50, 50, 350, 350); 82 83/* Create the Scatter chart object */ 84$myScatter = new Scatter($image, $data); 85 86/* Draw the scale */ 87$myScatter->drawScatterScale(); 88 89/* Turn on shadow computing */ 90$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]); 91 92/* Draw a scatter plot chart */ 93$myScatter->drawScatterLineChart(); 94 95/* Draw the legend */ 96$myScatter->drawScatterLegend(280, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]); 97 98/* Render the picture (choose the best way) */ 99$image->autoOutput("example.drawScatterLineChart.png"); 100``` 101