1# Drawing a stacked bar chart 2 3[Reference](http://wiki.pchart.net/doc.chart.drawstackedbarchart.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([-7, -8, -15, -20, -18, -12, 8, -19, 9, 16, -20, 8, 10, -10, -14, -20, 8, -9, -19], "Probe 3"); 14$data->addPoints([19, 0, -8, 8, -8, 12, -19, -10, 5, 12, -20, -8, 10, -11, -12, 8, -17, -14, 0], "Probe 4"); 15$data->setAxisName(0, "Temperatures"); 16$data->addPoints([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], "Time"); 17$data->setSerieDescription("Time", "Hour of the day"); 18$data->setAbscissa("Time"); 19$data->setXAxisUnit("h"); 20 21/* Create the Image object */ 22$image = new Image(700, 230, $data); 23 24/* Draw the background */ 25$settings = [ 26 "R" => 170, 27 "G" => 183, 28 "B" => 87, 29 "Dash" => 1, 30 "DashR" => 190, 31 "DashG" => 203, 32 "DashB" => 107 33]; 34$image->drawFilledRectangle(0, 0, 700, 230, $settings); 35 36/* Overlay with a gradient */ 37$settings = [ 38 "StartR" => 219, 39 "StartG" => 231, 40 "StartB" => 139, 41 "EndR" => 1, 42 "EndG" => 138, 43 "EndB" => 68, 44 "Alpha" => 50 45]; 46$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings); 47 48/* Set the default font properties */ 49$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]); 50 51/* Draw the scale */ 52$image->setGraphArea(60, 30, 650, 190); 53$image->drawScale([ 54 "CycleBackground" => true, 55 "DrawSubTicks" => true, 56 "GridR" => 0, 57 "GridG" => 0, 58 "GridB" => 0, 59 "GridAlpha" => 10, 60 "Mode" => SCALE_MODE_ADDALL 61]); 62 63/* Turn on shadow computing */ 64$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]); 65 66/* Draw some thresholds */ 67$image->setShadow(false); 68$image->drawThreshold(-40, ["WriteCaption" => true, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 4]); 69$image->drawThreshold(28, ["WriteCaption" => true, "R" => 0, "G" => 0, "B" => 0, "Ticks" => 4]); 70 71/* Draw the chart */ 72$image->drawStackedBarChart([ 73 "Rounded" => true, 74 "DisplayValues" => true, 75 "DisplayColor" => DISPLAY_AUTO, 76 "DisplaySize" => 6, 77 "BorderR" => 255, 78 "BorderG" => 255, 79 "BorderB" => 255 80]); 81 82/* Write the chart legend */ 83$image->drawLegend(570, 212, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]); 84 85/* Render the picture (choose the best way) */ 86$image->autoOutput("example.drawStackedBarChart.rounded.png"); 87``` 88