array( 'desc' => '5 days', 'labels' => 5, 'period' => 4, 'sql' => 'SELECT * FROM dpsi WHERE date > ( NOW() - INTERVAL 7 DAY )', ), 1 => array( 'desc' => '3 months', 'labels' => 3, 'period' => 3, 'sql' => 'SELECT * FROM dpsi WHERE date > ( NOW() - INTERVAL 3 MONTH )', 'size' => 65, ), 2 => array( 'desc' => '6 months', 'labels' => 6, 'period' => 6, 'sql' => 'SELECT * FROM dpsi WHERE date > ( NOW() - INTERVAL 6 MONTH )', 'size' => 130, ), 3 => array( 'desc' => '1 year', 'labels' => 6, 'period' => 12, 'sql' => 'SELECT * FROM dpsi WHERE date > ( NOW() - INTERVAL 12 MONTH )', 'size' => 260, ), ); # Define some useful stuff $year = array( -11 => 'Jan', -10 => 'Feb', -9 => 'Mar', -8 => 'Apr', -7 => 'May', -6 => 'Jun', -5 => 'Jul', -4 => 'Aug', -3 => 'Sep', -2 => 'Oct', -1 => 'Nov', 0 => 'Dec', 1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr', 5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep', 10 => 'Oct', 11 => 'Nov', 12 => 'Dec'); $week = array( -4 => 'Mon', -3 => 'Tue', -2 => 'Wed', -1 => 'Thu', 0 => 'Fri', 1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu', 5 => 'Fri'); # Mode parameter $display = @ intval($_REQUEST['mode']); include ("graph/jpgraph.php"); include ("graph/jpgraph_line.php"); $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); mysql_select_db(DB_NAME); $result = mysql_query($mode[$display]['sql'] . ' ORDER BY DATE ASC'); while ($row = mysql_fetch_assoc($result)) { $data[] = $row['value']; } mysql_free_result($result); # Generate an empty array if(!empty($mode[$display]['size'])) { for ($i=0;$i<$mode[$display]['size'];$i++) { $datahash[] = false; } $counter = sizeof($data); for (;$i>-1;$i--) { $datahash[$i] = $data[--$counter]; } } else { $datahash = $data; } # Generate an empty array $graph = new Graph($width,$height); $graph->SetAlphaBlending(); $graph->SetFrame(false); $graph->SetMargin(30,30,25,25); $graph->SetScale("textlin"); $graph->yaxis->HideTicks(true,true); $graph->yaxis->SetColor('gray','darkgray'); $graph->yaxis->SetPos('max'); $graph->yaxis->SetLabelSide(SIDE_RIGHT); if($display) { $month = date('m') - $mode[$display]['period']; $day = date('j'); $step = round(sizeof($datahash)/$mode[$display]['labels']); for ($i=0;$i<=$mode[$display]['labels'];$i++) { $label[$i*$step] = $year[$month + $i*$mode[$display]['period']/$mode[$display]['labels']].','.$day; } } else { $wday = date('w', time() - 17*3600); # Shift current day at 17 hrs to the past if ($wday == 0 || $wday == 6 ) { $wday = 5; } $day = $wday - $mode[$display]['period']; $step = 1; for ($i=0;$i<=$mode[$display]['labels'];$i++) { $label[$i] = $week[$day + $i]; } } $graph->xaxis->HideTicks(true,true); $graph->xaxis->SetColor('gray','darkgray'); $graph->xaxis->SetTextTickInterval($step); $graph->xaxis->SetTextLabelInterval(1); $graph->xaxis->SetTickLabels($label); $graph->xgrid->Show(); $graph->xgrid->SetColor('lightgray'); $graph->xgrid->Show(true, false); $graph->ygrid->Show(); $graph->ygrid->SetColor('lightgray'); $p1 = new LinePlot($datahash); $p1->SetColor("deepskyblue"); $p1->SetFillColor("lightblue@0.4"); $caption=new Text('DPSI - TheDomains.com ('.$mode[$display]['desc'].')',round($width/2),2); $caption->SetColor('darkgray'); $caption->SetAlign('center'); $graph->AddText($caption); $graph->Add($p1); $graph->Stroke(); ?>