예제 #1
0
$lineChart->setLegend(array("first"));<br>
$lineChart->setColors(array("ff3344"));<br>
$lineChart->setVisibleAxes(array('x','y'));<br>
$lineChart->setDataRange(30,130);<br>
$lineChart->addAxisRange(0, 1, 4, 1);<br>
$lineChart->addAxisRange(1, 30, 130);<br>
$lineChart->addLineFill('B','76A4FB',0,0);<br>
</code>
</p>
<h2>Line Chart with Grid Lines</h2>
<?php 
$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);
?>
<img src="<?php 
print $lineChart->getUrl();
?>
" /> <br> line chart using the gLineChart class.
<p>
<em>code:</em><br>
<code>
$lineChart = new gLineChart(300,300);<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;
     }
 }
예제 #3
0
파일: img.php 프로젝트: Adrielpin/gchartphp
<?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']);
예제 #4
0
            $data[] = $value->p_in;
            if ($i % 90 == 0) {
                $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>
예제 #5
0
    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());
    }