1# Drawing a scatter spline chart 2 3[Reference](http://wiki.pchart.net/doc.scatter.drawscattersplineChart.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 + 90) { 17 $data->addPoints(rand(1, 30), "Probe 1"); 18} 19for ($i = 0; $i <= 360; $i = $i + 90) { 20 $data->addPoints(rand(1, 30), "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 + 90) { 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/* Create the 2nd scatter chart binding */ 42$data->setScatterSerie("Probe 2", "Probe 3", 1); 43$data->setScatterSerieDescription(1, "Last Year"); 44 45/* Create the Image object */ 46$image = new Image(400, 400, $data); 47 48/* Draw the background */ 49$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107]; 50$image->drawFilledRectangle(0, 0, 400, 400, $settings); 51 52/* Overlay with a gradient */ 53$settings = [ 54 "StartR" => 219, 55 "StartG" => 231, 56 "StartB" => 139, 57 "EndR" => 1, 58 "EndG" => 138, 59 "EndB" => 68, 60 "Alpha" => 50 61]; 62$image->drawGradientArea(0, 0, 400, 400, DIRECTION_VERTICAL, $settings); 63$image->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, [ 64 "StartR" => 0, 65 "StartG" => 0, 66 "StartB" => 0, 67 "EndR" => 50, 68 "EndG" => 50, 69 "EndB" => 50, 70 "Alpha" => 80 71]); 72 73/* Write the picture title */ 74$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 75$image->drawText(10, 13, "drawScatterSplineChart() - Draw a scatter spline chart", [ 76 "R" => 255, 77 "G" => 255, 78 "B" => 255 79]); 80 81/* Add a border to the picture */ 82$image->drawRectangle(0, 0, 399, 399, ["R" => 0, "G" => 0, "B" => 0]); 83 84/* Set the default font */ 85$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 86 87/* Set the graph area */ 88$image->setGraphArea(50, 50, 350, 350); 89 90/* Create the Scatter chart object */ 91$myScatter = new Scatter($image, $data); 92 93/* Draw the scale */ 94$myScatter->drawScatterScale(); 95 96/* Turn on shadow computing */ 97$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]); 98 99/* Draw a scatter plot chart */ 100$myScatter->drawScatterSplineChart(); 101$myScatter->drawScatterPlotChart(); 102 103/* Draw the legend */ 104$myScatter->drawScatterLegend(280, 380, ["Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER]); 105 106/* Render the picture (choose the best way) */ 107$image->autoOutput("example.drawScatterSplineChart.png"); 108``` 109