public static function build_pireptable($pilotid, $days = '30', $color = '000000', $background = 'EFEFEF', $width = '950', $height = '260')
 {
     #make sure $days is even - if not add 1
     if ($days & 1) {
         $days++;
     }
     $output = array();
     #set current date
     $month = date("m");
     $day = date("d");
     $year = date("Y");
     #set todays date
     $output[] = date('m-d', mktime(0, 0, 0, $month, $day, $year));
     #loop through days
     for ($i = 1; $i <= $days - 1; $i++) {
         $output[] = date('m-d', mktime(0, 0, 0, $month, $day - $i, $year));
     }
     #reverse the days for chart
     $output = array_reverse($output);
     #set baseline values
     $labels = array();
     $points = array();
     $xTotal = 0;
     $yTotal = 0;
     $dataPoint = array();
     $data = PIREPData::getIntervalDataByDays(array('p.pilotid' => $pilotid), $days);
     if ($data) {
         foreach ($data as $dat) {
             $points[] = $dat->total;
             #get highest y-axis value for chart
             if ($dat->total > $total) {
                 $yTotal = $dat->total;
             }
             $date = '';
             $date = explode('-', $dat->ym);
             $labels[] = $date[1] . '-' . $date[2];
             $xTotal++;
             $z = new stdClass();
             $z->label = $date[1] . '-' . $date[2];
             $z->point = $dat->total;
             $dataPoint[] = $z;
         }
     }
     $fLabels = array();
     $fPoints = array();
     $arraySpot = '0';
     foreach ($output as $num => $point) {
         #display every x-axis label on charts 10 days or less
         if ($days < 11) {
             if (in_array($point, $labels)) {
                 $fLabels[] = $dataPoint[$arraySpot]->label;
                 $fPoints[] = $dataPoint[$arraySpot]->point;
                 $arraySpot++;
             } else {
                 $fLabels[] = $point;
                 $fPoints[] = '0';
             }
         } else {
             if (in_array($point, $labels)) {
                 if ($num & 1) {
                     $fLabels[] = $dataPoint[$arraySpot]->label;
                 } else {
                     $fLabels[] = '';
                 }
                 $fPoints[] = $dataPoint[$arraySpot]->point;
                 $arraySpot++;
             } else {
                 if ($num & 1) {
                     $fLabels[] = $point;
                 } else {
                     $fLabels[] = '';
                 }
                 $fPoints[] = '0';
             }
         }
     }
     #build chart params
     $lineChart = new gLineChart($width, $height);
     $lineChart->addDataSet($fPoints);
     $lineChart->setColors(array($color));
     $lineChart->setVisibleAxes(array('x', 'y'));
     $lineChart->setDataRange(0, $yTotal + 1);
     $lineChart->addAxisRange(0, 1, $days, 1);
     $lineChart->addAxisRange(1, 0, $yTotal + 1, 1);
     $lineChart->setlineMarkers('6');
     $lineChart->setlineWidth('1');
     $lineChart->setaxisStyle('0', $color, '10');
     $lineChart->addAxisLabel(0, $fLabels);
     $lineChart->setGridLines(100 / 29, 100 / ($yTotal + 1), 4, 2, 0, 0);
     $lineChart->setTitle("Last " . $days . " Days PIREPS");
     $lineChart->setTitleOptions($color, '18');
     $lineChart->setChartMargins(array(20, 20, 20, 20));
     $lineChart->addBackgroundFill('bg', $background);
     return $lineChart->getUrl();
 }
$barChart->addHiddenDataSet(array(10,0,20,15,60,40,30));<br>
$barChart->addValueMarkers('D','76A4FB',2,0,3);<br>
$barChart->setAutoBarWidth();<br>
</code>
</p>
<h2>Candlestick Chart</h2>
<?php 
$candlestick = new gLineChart(200, 125);
$candlestick->addDataSet(array(90, 80, 70, 50, 40, 30, 20, 10));
$candlestick->addHiddenDataSet(array(0, 5, 10, 0, 5, 10, 0));
$candlestick->addHiddenDataSet(array(2, 15, 20, 5, 15, 40, 0));
$candlestick->addHiddenDataSet(array(5, 35, 20, 2, 35, 20, 0));
$candlestick->addHiddenDataSet(array(15, 40, 30, 15, 40, 50, 0));
$candlestick->addValueMarkers('F', '000000', 1, '1:-2', 20);
$candlestick->setVisibleAxes(array('y'));
$candlestick->addAxisRange(0, 0, 100);
?>
<img src="<?php 
print $candlestick->getUrl();
?>
" /> <br> compound bar chart using the gGroupedBarChart class and addValueMarkers().
<p>
<em>code:</em><br>
<code>
$candlestick = new gLineChart(200,125);<br>
$candlestick -> addDataSet(array(90,80,70,50,40,30,20,10));<br>
$candlestick -> addHiddenDataSet(array(0,5,10,0,5,10,0));<br>
$candlestick -> addHiddenDataSet(array(2,15,20,5,15,40,0));<br>
$candlestick -> addHiddenDataSet(array(5,35,20,2,35,20,0));<br>
$candlestick -> addHiddenDataSet(array(15,40,30,15,40,50,0));<br>
$candlestick -> addValueMarkers('F','000000',1,'1:-2',20);<br>
 /**
  * Generate the dashboard with the google analytics graphs
  *
  * @return void
  */
 public function indexAction()
 {
     $params = Zend_Registry::get('params');
     $this->view->currentPage = 'dashboard';
     try {
         $email = $params->googleAnalytics->username;
         $password = $params->googleAnalytics->password;
         $profileID = $params->googleAnalytics->homeletProfileID;
         $client = Zend_Gdata_ClientLogin::getHttpClient($email, $password, Zend_Gdata_Analytics::AUTH_SERVICE_NAME);
         $service = new Zend_Gdata_Analytics($client);
         $firstOfMonth = date("Y-m-d", strtotime(date('m') . '/01/' . date('Y') . ' 00:00:00'));
         $today = date("Y-m-d");
         $this->view->startDate = date("d/m/Y", strtotime($firstOfMonth));
         $this->view->today = date("d/m/Y", strtotime($today));
         // LINE CHART for visitors this month
         $query = $service->newDataQuery()->setProfileId($profileID)->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_DAY)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)->setStartDate($firstOfMonth)->setEndDate($today)->setSort(Zend_Gdata_Analytics_DataQuery::DIMENSION_DAY, false)->setMaxResults(25);
         $result = $service->getDataFeed($query);
         $chartArray = array();
         foreach ($result as $row) {
             $chartArray[] = (int) $row->getValue('ga:visits')->getValue();
         }
         $visitorsChart = new gLineChart(800, 200);
         $visitorsChart->addDataSet($chartArray);
         $visitorsChart->setLegend(array('Site Visitors'));
         $visitorsChart->setColors(array('FF6D1B'));
         $visitorsChart->setVisibleAxes(array('x', 'y'));
         $visitorsChart->setDataRange(0, 7000);
         $visitorsChart->setLegendPosition('t');
         $visitorsChart->addAxisRange(0, 0, count($chartArray), 2);
         $visitorsChart->addAxisRange(1, 0, 7000);
         $visitorsChart->setGridLines(7, 1000);
         $this->view->visitorGraphUrl = $visitorsChart->getUrl();
         // PIE CHART for sources
         $query = $service->newDataQuery()->setProfileId($profileID)->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_MEDIUM)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)->setStartDate($firstOfMonth)->setEndDate($today)->setSort(Zend_Gdata_Analytics_DataQuery::DIMENSION_MEDIUM, false)->setMaxResults(500);
         $result = $service->getDataFeed($query);
         $chartArray = array();
         $colorArray = array();
         $labelArray = array();
         foreach ($result as $row) {
             $chartArray[] = (int) $row->getValue('ga:visits')->getValue();
             switch ((string) $row->getValue('ga:medium')->getValue()) {
                 case '(none)':
                     $medium = 'Direct';
                     $color = 'FF6F1C';
                     break;
                 case 'email':
                     $medium = 'Email Campaign';
                     $color = 'FDBB30';
                     break;
                 case 'organic':
                     $medium = 'Search Engines';
                     $color = '7AC142';
                     break;
                 case 'referral':
                     $medium = 'Referring Site';
                     $color = 'E60E64';
                     break;
                 default:
                     $medium = (string) $row->getValue('ga:medium')->getValue();
             }
             $labelArray[] = $medium;
             $colorArray[] = $color;
         }
         $sourcesChart = new gPieChart(380, 200);
         $sourcesChart->addDataSet($chartArray);
         $sourcesChart->setLegend($labelArray);
         $sourcesChart->setColors($colorArray);
         $this->view->sourcesGraphUrl = $sourcesChart->getUrl();
         // Table of top 20 keywords
         $query = $service->newDataQuery()->setProfileId($profileID)->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_KEYWORD)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)->setStartDate($firstOfMonth)->setEndDate($today)->setSort(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS, true)->setMaxResults(20);
         $result = $service->getDataFeed($query);
         $keywordArray = array();
         foreach ($result as $row) {
             $keyword = (string) $row->getValue('ga:keyword')->getValue();
             if ($keyword == '(not set)') {
                 $keyword = '-';
             }
             $keywordArray[$keyword] = (int) $row->getValue('ga:visits')->getValue();
         }
         $this->view->keywordList = $keywordArray;
         // PIE CHART for new/returning visitors
         $query = $service->newDataQuery()->setProfileId($profileID)->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_VISITOR_TYPE)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS)->setStartDate($firstOfMonth)->setEndDate($today)->setSort(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS, true)->setMaxResults(2);
         $result = $service->getDataFeed($query);
         $chartArray = array();
         $colorArray = array();
         $labelArray = array();
         foreach ($result as $row) {
             $chartArray[] = (int) $row->getValue('ga:visits')->getValue();
             $labelArray[] = (string) $row->getValue('ga:visitorType')->getValue();
             switch ((string) $row->getValue('ga:visitorType')->getValue()) {
                 case 'Returning Visitor':
                     $color = 'FF6F1C';
                     break;
                 case 'New Visitor':
                     $color = '7AC142';
                     break;
                 default:
             }
             $colorArray[] = $color;
         }
         $newReturningChart = new gPieChart(380, 200);
         $newReturningChart->addDataSet($chartArray);
         $newReturningChart->setLegend($labelArray);
         $newReturningChart->setColors($colorArray);
         $this->view->newReturningUrl = $newReturningChart->getUrl();
     } catch (Exception $e) {
         $this->view->statsUnavailable = true;
     }
 }
Beispiel #4
0
 function createChart($stats)
 {
     $data = array();
     $nb_jour = 0;
     $temp = "";
     $date_differente = array();
     foreach ($stats as $row) {
         $data[] = $row[1];
         //le nombre d'auditeurs
         list($date[], $heure[]) = explode(' ', $row[2]);
         //les horaires
     }
     //on compte le nombre de jour différents
     foreach ($date as $test) {
         if ($test != $temp) {
             $temp = $test;
             $nb_jour = $nb_jour + 1;
             list($annee, $mois, $jour) = explode('-', $test);
             $date_differente[] = $jour . "-" . $mois;
         }
     }
     //Ajout de la date de demain, pour le dernier label de l'axe sur 7 jours
     $date_differente[] = "Maintenant";
     //calcul des valeurs maximales
     $max_auditeurs = ceil(max($data) / 10) * 10;
     //nb max d'auditeurs arrondi à la dizaine supérieure
     //$nb_jour=count($date);//compte le nb de jour présent dans les stats
     if ($nb_jour == 1) {
         $max_horaire = max($heure) + 1;
         //si un seul jour de stat, on regarde l'heure maximale connue pour ajuster l'axe des abscisses
         list($max_heure, $max_minute, $max_seconde) = explode(':', $max_horaire);
     } else {
         $max_heure = $nb_jour;
     }
     $nb_valeur = count($data);
     //largeur du graphique
     $size = $nb_valeur * 6;
     $size = $size > 1000 ? 1000 : $size;
     $size = $size < 300 ? 300 : $size;
     $lineChart = new gLineChart($size, 300);
     /*if ($max_auditeurs>100)
     		{
     		//$lineChart->setEncodingType('e');
     		}*/
     $lineChart->addDataSet($data);
     //$lineChart->setLegend(array("first"));
     $lineChart->setColors(array("ff3344"));
     $lineChart->setVisibleAxes(array('x', 'y'));
     $lineChart->setDataRange(0, $max_auditeurs);
     $lineChart->addAxisRange(0, 0, $max_heure, 1);
     $lineChart->addAxisRange(1, 0, $max_auditeurs);
     $lineChart->addLineFill('B', '76A4FB', 0, 0);
     if ($nb_jour > 1) {
         $lineChart->addAxisLabel(0, $date_differente);
     }
     if ($max_auditeurs != 0) {
         $lineChart->setGridLines(0, 1000 / $max_auditeurs);
     }
     //$lineChart->addAxisLabel(0, $heure);
     $chart = $lineChart->getUrl();
     return $chart;
 }
                $timestamps[] = date('H:i', $value->timestamp);
            }
        }
    }
    $i++;
}
for ($i = 2; $i < count($data); $i++) {
    $averages[] = round(($data[$i] + $data[$i - 1] + $data[$i - 2]) / 3);
}
$averages = array_reverse($averages);
$p_in = round($averages[count($averages) - 1]);
$lineChart = new gLineChart(700, 400);
$lineChart->addDataSet($averages);
$lineChart->setLegend(array("People"));
$lineChart->setColors(array("ff3344"));
$lineChart->setVisibleAxes(array('x', 'y'));
$lineChart->setDataRange(0, 1000);
$lineChart->addAxisRange(1, 0, 1000);
$lineChart->addAxisLabel(0, $timestamps);
$lineChart->addLineFill(B, '76A4FB', 0, 0);
$lineChart->setGridLines(100, 10);
$url = $lineChart->getUrl();
print "<p><h1>{$name}</h1></p>";
print "Number of people currently at the station: {$p_in} <br/>";
print "<img src='{$url}' />";
print "<br/><i>A graph showing the number of people at {$name} station over the last day</i><br/>";
?>
</div>
</body>
</html>
Beispiel #6
0
<?php

require_once "gChart.php";
$lineChart = new gLineChart($_GET['width'], $_GET['height']);
$lineChart->addDataSet(array(120, 131, 135, 160, 129, 22, 190));
$lineChart->setLegend(array('Nice figures'));
$lineChart->setColors(array('ED237A'));
$lineChart->setVisibleAxes(array('x', 'y'));
$lineChart->setDataRange(0, 200);
$lineChart->setLegendPosition('t');
// axisnr, from, to, step
$lineChart->addAxisRange(0, 0, 28, 7);
$lineChart->addAxisRange(1, 0, 200);
$lineChart->setGridLines(25, 10);
$lineChart->renderImage($_GET['post']);
    function test_LineChart_GridLines()
    {
        $lineChart = new gLineChart(300, 300);
        $lineChart->addDataSet(array(112, 315, 66, 40));
        $lineChart->addDataSet(array(212, 115, 366, 140));
        $lineChart->addDataSet(array(112, 95, 116, 140));
        $lineChart->setLegend(array("first", "second", "third", "fourth"));
        $lineChart->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
        $lineChart->setVisibleAxes(array('x', 'y'));
        $lineChart->setDataRange(0, 400);
        $lineChart->addAxisRange(0, 1, 4, 1);
        $lineChart->addAxisRange(1, 0, 400);
        $lineChart->setGridLines(33, 10);
        $text = <<<END
newLineChart: 300,300
addDataSet: 112,315,66,40
addDataSet: 212,115,366,140
addDataSet: 112,95,116,140
setLegend: first, second, third, fourth
setColors: ff3344, 11ff11, 22aacc, 3333aa
setVisibleAxes: x, y
setDataRange: 0, 400
addAxisRange: 0, 1, 4, 1
addAxisRange: 1, 0, 400
setGridLines: 33,10

END;
        $parser = new gChartPhpDSLParser();
        $parser->parse($text);
        $this->assertEqual($lineChart->getUrl(), $parser->getUrl());
    }