[42] | 1 | <?php // content="text/plain; charset=utf-8"
|
---|
| 2 | require_once ('../jpgraph.php');
|
---|
| 3 | require_once ('../jpgraph_mgraph.php');
|
---|
| 4 | require_once ('../jpgraph_line.php');
|
---|
| 5 | require_once ('../jpgraph_bar.php');
|
---|
| 6 | require_once ('../jpgraph_utils.inc.php');
|
---|
| 7 |
|
---|
| 8 | //------------------------------------------------------------------
|
---|
| 9 | // Create some random data for the plot. We use the current time for the
|
---|
| 10 | // first X-position
|
---|
| 11 | //------------------------------------------------------------------
|
---|
| 12 | $datay = array();
|
---|
| 13 | $datax = array();
|
---|
| 14 | $ts = time();
|
---|
| 15 | $n=70; // Number of data points
|
---|
| 16 | for($i=0; $i < $n; ++$i ) {
|
---|
| 17 | $datax[$i] = $ts+$i*150000;
|
---|
| 18 | $datay[$i] = rand(5,60);
|
---|
| 19 | $datay2[$i] = rand(1,8);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | // Now get labels at the start of each month
|
---|
| 23 | list($tickPositions,$minTickPositions) = DateScaleUtils::getTicks($datax,DSUTILS_MONTH1);
|
---|
| 24 |
|
---|
| 25 | // Now create the real graph
|
---|
| 26 | // Combine a line and a bar graph
|
---|
| 27 |
|
---|
| 28 | // We add some grace to the end of the X-axis scale so that the first and last
|
---|
| 29 | // data point isn't exactly at the very end or beginning of the scale
|
---|
| 30 | $grace = 400000;
|
---|
| 31 | $xmin = $datax[0]-$grace;
|
---|
| 32 | $xmax = $datax[$n-1]+$grace;;
|
---|
| 33 |
|
---|
| 34 | // Overall width of graphs
|
---|
| 35 | $w = 450;
|
---|
| 36 | // Left and right margin for each graph
|
---|
| 37 | $lm=25; $rm=15;
|
---|
| 38 |
|
---|
| 39 | //----------------------
|
---|
| 40 | // Setup the line graph
|
---|
| 41 | //----------------------
|
---|
| 42 | $graph = new Graph($w,250);
|
---|
| 43 | $graph->SetScale('linlin',0,0,$xmin,$xmax);
|
---|
| 44 | $graph->SetMargin($lm,$rm,10,30);
|
---|
| 45 | $graph->SetMarginColor('white');
|
---|
| 46 | $graph->SetFrame(false);
|
---|
| 47 | $graph->SetBox(true);
|
---|
| 48 | $graph->title->Set('Example of combined graph with background');
|
---|
| 49 | $graph->title->SetFont(FF_ARIAL,FS_NORMAL,14);
|
---|
| 50 | $graph->xaxis->SetTickPositions($tickPositions,$minTickPositions);
|
---|
| 51 | $graph->xaxis->SetLabelFormatString('My',true);
|
---|
| 52 | $graph->xgrid->Show();
|
---|
| 53 | $p1 = new LinePlot($datay,$datax);
|
---|
| 54 | $graph->Add($p1);
|
---|
| 55 |
|
---|
| 56 | //----------------------
|
---|
| 57 | // Setup the bar graph
|
---|
| 58 | //----------------------
|
---|
| 59 | $graph2 = new Graph($w,110);
|
---|
| 60 | $graph2->SetScale('linlin',0,0,$xmin,$xmax);
|
---|
| 61 | $graph2->SetMargin($lm,$rm,5,10);
|
---|
| 62 | $graph2->SetMarginColor('white');
|
---|
| 63 | $graph2->SetFrame(false);
|
---|
| 64 | $graph2->SetBox(true);
|
---|
| 65 | $graph2->xgrid->Show();
|
---|
| 66 | $graph2->xaxis->SetTickPositions($tickPositions,$minTickPositions);
|
---|
| 67 | $graph2->xaxis->SetLabelFormatString('My',true);
|
---|
| 68 | $graph2->xaxis->SetPos('max');
|
---|
| 69 | $graph2->xaxis->HideLabels();
|
---|
| 70 | $graph2->xaxis->SetTickSide(SIDE_DOWN);
|
---|
| 71 | $b1 = new BarPlot($datay2,$datax);
|
---|
| 72 | $b1->SetFillColor('teal');
|
---|
| 73 | $b1->SetColor('teal:1.2');
|
---|
| 74 | $graph2->Add($b1);
|
---|
| 75 |
|
---|
| 76 | //-----------------------
|
---|
| 77 | // Create a multigraph
|
---|
| 78 | //----------------------
|
---|
| 79 | $mgraph = new MGraph();
|
---|
| 80 | $mgraph->SetImgFormat('jpeg',60);
|
---|
| 81 | $mgraph->SetMargin(2,2,2,2);
|
---|
| 82 | $mgraph->SetFrame(true,'darkgray',2);
|
---|
| 83 | $mgraph->SetBackgroundImage('tiger1.jpg');
|
---|
| 84 | $mgraph->AddMix($graph,0,0,85);
|
---|
| 85 | $mgraph->AddMix($graph2,0,250,85);
|
---|
| 86 | $mgraph->Stroke();
|
---|
| 87 |
|
---|
| 88 | ?>
|
---|
| 89 |
|
---|
| 90 |
|
---|