1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| $data_on = array(11,7,5,8,3,5,5,4,8,6,5,5,3,2,5,1,2,3);
$data_off = array(4,5,4,5,4,5,6,4,7,4,4,3,2,3,1,1,2,1);
$datay1=array();
$datay2=array();
$nb_val=sizeof($data_on);
for($i=0;$i<$nb_val;$i++)
{
$datay1[$i] = $data_on[$i];
if($data_on[$i]>=$data_off[$i])
{
$datay2[$i] = 0;
}
else
{
$datay2[$i] = $data_off[$i]-$data_on[$i];
}
}
// Create the graph. These two calls are always required
$graph = new Graph(600,400);
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,20,40);
$p2 = new LinePlot($data_off);
// Create the linear plots for each category
$dplot[] = new LinePLot($datay1);
$dplot[] = new LinePLot($datay2);
// $dplot[] = new LinePLot($datay3);
$dplot[0]->SetFillColor("green");
$dplot[1]->SetFillColor("red");
// $dplot[2]->SetFillColor("red");
// Create the accumulated graph
$accplot = new AccLinePlot($dplot);
// Add the plot to the graph
$graph->Add($accplot);
$graph->Add($p2);
$p2->SetColor("black");
$graph->xaxis->SetTextTickInterval(2);
$graph->title->Set("Example 17");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
// Display the graph
$graph->Stroke(); |