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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| <?php
require_once("../include/Util.php");
require_once ("../include/jpgraph/jpgraph.php");
require_once ("../include/jpgraph/jpgraph_line.php");
require_once ("../include/jpgraph/jpgraph_date.php");
require_once ("../include/jpgraph/jpgraph_bar.php");
// Create a data set in range (50,70) and X-positions
DEFINE('NDATAPOINTS',36);
DEFINE('SAMPLERATE',240);
$start = time();
$end = $start+NDATAPOINTS*SAMPLERATE;
$data_1 = array();
$xdata_1 = array();
$data_2 = array();
$xdata_2 = array();
$data_3 = array();
$xdata_3 = array();
$data_4 = array();
$xdata_4 = array();
for( $i=0; $i <= NDATAPOINTS/2; ++$i ) {
$data_1[$i] = rand(0,30) -$i;
$xdata_1[$i] = $start + $i * SAMPLERATE;
}
for( $i=0; $i < NDATAPOINTS/2; ++$i ) {
$data_2[$i] = rand(-20,30)-$i;
$xdata_2[$i] = $start + ($i +NDATAPOINTS/2)* SAMPLERATE;
}
for( $i=0; $i <= NDATAPOINTS/2; ++$i ) {
if($i!='0')
{
$data_3[$i] = $data_3[$i-1]+$data_1[$i];
}
else
{
$data_3['0']= $data_1['0'];
}
$xdata_3[$i] = $start + $i * SAMPLERATE;
}
for( $i=0; $i < NDATAPOINTS/2; ++$i ) {
if ($i!='0')
{
$data_4[$i] = $data_4[$i-1]+$data_2[$i];
}
else
{
$i_max=floor(NDATAPOINTS/2);
$data_4['0']= $data_2['0']+$data_3[$i_max];
}
$xdata_4[$i] = $start + ($i +NDATAPOINTS/2)* SAMPLERATE;
}
// Create the new graph
$graph = new Graph(600,300);
// Slightly larger than normal margins at the bottom to have room for
// the x-axis labels
$graph->SetMargin(40,40,30,130);
// Fix the Y-scale to go between [0,100] and use date for the x-axis
$graph->SetScale('datlin',0,100);
$graph->title->Set("Example on Date scale");
// Set the angle for the labels to 90 degrees
$graph->xaxis->SetLabelAngle(90);
// The automatic format string for dates can be overridden
$graph->xaxis->scale->SetDateFormat('H:i');
// Adjust the start/end to a specific alignment
$graph->xaxis->scale->SetTimeAlign(MINADJ_10);
$plot_1 = new BarPlot($data_1,$xdata_1);
$plot_1->SetLegend('Year 2005');
$plot_1->SetFillColor('blue@0.5');
$graph->Add($plot_1);
$plot_2 = new BarPlot($data_2,$xdata_2);
$plot_2->SetLegend('Year 2006');
$plot_2->SetFillColor('red@0.5');
$graph->Add($plot_2);
$line_3 = new linePlot($data_3,$xdata_3);
$line_3->SetFillColor('lightblue@0.5');
$graph->Add($line_3);
$line_4 = new linePlot($data_4,$xdata_4);
$line_4->SetFillColor('lightred@0.5');
$graph->Add($line_4);
$graph->Stroke();
?> |
Partager