1# Drawing a step chart 2 3[Reference](http://wiki.pchart.net/doc.chart.drawstepchart.html) 4 5```php 6require '/path/to/your/vendor/autoload.php'; 7 8use CpChart\Data; 9use CpChart\Image; 10 11/* Create and populate the Data object */ 12$data = new Data(); 13$data->addPoints([-4, VOID, VOID, 12, 8, 3], "Probe 1"); 14$data->addPoints([3, 12, 15, 8, 5, -5], "Probe 2"); 15$data->addPoints([2, 7, 5, 18, 19, 22], "Probe 3"); 16$data->setSerieTicks("Probe 2", 4); 17$data->setAxisName(0, "Temperatures"); 18$data->addPoints(["Jan", "Feb", "Mar", "Apr", "May", "Jun"], "Labels"); 19$data->setSerieDescription("Labels", "Months"); 20$data->setAbscissa("Labels"); 21 22/* Create the Image object */ 23$image = new Image(700, 230, $data); 24 25/* Draw the background */ 26$settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107]; 27$image->drawFilledRectangle(0, 0, 700, 230, $settings); 28 29/* Overlay with a gradient */ 30$settings = [ 31 "StartR" => 219, 32 "StartG" => 231, 33 "StartB" => 139, 34 "EndR" => 1, 35 "EndG" => 138, "EndB" => 68, "Alpha" => 50 36]; 37$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings); 38$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [ 39 "StartR" => 0, 40 "StartG" => 0, 41 "StartB" => 0, 42 "EndR" => 50, 43 "EndG" => 50, 44 "EndB" => 50, 45 "Alpha" => 80 46]); 47 48/* Add a border to the picture */ 49$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]); 50 51/* Write the picture title */ 52$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 53$image->drawText(10, 13, "drawStepChart() - draw a step chart", ["R" => 255, "G" => 255, "B" => 255]); 54 55/* Write the chart title */ 56$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11]); 57$image->drawText(250, 55, "Average temperature", ["FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE]); 58 59/* Draw the scale and the 1st chart */ 60$image->setGraphArea(60, 60, 450, 190); 61$image->drawFilledRectangle(60, 60, 450, 190, [ 62 "R" => 255, 63 "G" => 255, 64 "B" => 255, 65 "Surrounding" => -200, 66 "Alpha" => 10 67]); 68$image->drawScale(["DrawSubTicks" => true]); 69$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]); 70$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 71$image->drawStepChart(["DisplayValues" => true, "DisplayColor" => DISPLAY_AUTO]); 72$image->setShadow(false); 73 74/* Draw the scale and the 2nd chart */ 75$image->setGraphArea(500, 60, 670, 190); 76$image->drawFilledRectangle(500, 60, 670, 190, [ 77 "R" => 255, 78 "G" => 255, 79 "B" => 255, 80 "Surrounding" => -200, 81 "Alpha" => 10 82]); 83$image->drawScale(["Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => true]); 84$image->setShadow(true, ["X" => -1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]); 85$image->drawStepChart(); 86$image->setShadow(false); 87 88/* Write the chart legend */ 89$image->drawLegend(510, 205, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]); 90 91/* Render the picture (choose the best way) */ 92$image->autoOutput("example.drawStepChart.png"); 93``` 94