Ejemplo n.º 1
0
function prepareData($scaleX, $scaleY, $SQL, $scaleType)
{
    global $conn;
    $DataSet = new pData();
    $result = pg_query($conn, $SQL);
    if (!$result) {
        echo "An error occured.\n";
    }
    while ($row = pg_fetch_row($result)) {
        $DataSet->AddPoint($row[1], "Serie2");
        $DataSet->AddPoint(mktime(0, 0, 0, substr($row[0], 5, 2), substr($row[0], 8, 2), substr($row[0], 0, 4)), "Serie1");
    }
    $DataSet->SetAbsciseLabelSerie("Serie1");
    $DataSet->AddSerie("Serie2");
    $DataSet->SetYAxisName($scaleY);
    $DataSet->SetXAxisFormat($scaleType);
    return $DataSet;
}
Ejemplo n.º 2
0
// Standard inclusions
include "pChart/pData.class";
include "pChart/pChart.class";
// Dataset definition
$DataSet = new pData();
$DataSet->AddPoint(array(100, 320, 200, 10, 43), "Serie1");
$DataSet->AddPoint(array(23, 432, 43, 153, 234), "Serie2");
$DataSet->AddPoint(array(1217541600, 1217628000, 1217714400, 1217800800, 1217887200), "Serie3");
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("Incoming", "Serie1");
$DataSet->SetSerieName("Outgoing", "Serie2");
$DataSet->SetYAxisName("Call duration");
$DataSet->SetYAxisFormat("time");
$DataSet->SetXAxisFormat("date");
// Initialise the graph
$Test = new pChart(700, 230);
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->setGraphArea(85, 30, 650, 200);
$Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
$Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
$Test->drawGraphArea(255, 255, 255, TRUE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2);
$Test->drawGrid(4, TRUE, 230, 230, 230, 50);
// Draw the 0 line
$Test->setFontProperties("Fonts/tahoma.ttf", 6);
$Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
Ejemplo n.º 3
0
 protected function generateGraphImage($finalData, $hourflag, $title = 'Sticky Charts', $x_axis_format = 'date')
 {
     $path = $this->config->item('csv_upload_path');
     if (!empty($finalData['data'])) {
         $DataSet = new pData();
         $in = 0;
         foreach ($finalData['data'] as $seriesData) {
             $in++;
             $seriesIndex = 'Serie' . $in;
             $DataSet->AddPoint($seriesData['data'], $seriesIndex);
             $DataSet->SetSerieName($seriesData['name'], $seriesIndex);
             $DataSet->AddSerie($seriesIndex);
         }
         $xAxisArray = array();
         $in++;
         $seriesIndex = 'Serie' . $in;
         $catCount = count($finalData['cat']);
         if ($catCount <= 10) {
             $DataSet->SetXAxisFormat($x_axis_format);
         }
         foreach ($finalData['cat'] as $catD) {
             if ($catCount > 10) {
                 $xAxisArray[] = '';
             } else {
                 $xAxisArray[] = strtotime($catD);
             }
         }
         $DataSet->SetYAxisFormat("number");
         $DataSet->AddPoint($xAxisArray, $seriesIndex);
         $DataSet->SetAbsciseLabelSerie($seriesIndex);
         $DataSet->SetYAxisName($finalData['y_title']);
         $DataSet->SetXAxisName($finalData['x_title']);
         // Initialise the graph
         $Test = new pChart(985, 458);
         $Test->drawBackground(247, 226, 180);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
         $Test->setGraphArea(40, 30, 950, 400);
         $Test->drawGraphArea(109, 110, 114, false);
         $Test->drawGrid(4, false, 0, 0, 0, 50);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 6);
         // Draw the line graph
         if ($title == 'Violation Report') {
             //!$hourflag &&
             $sCount = count($finalData['data']);
             if ($sCount > 0) {
                 for ($m = 0; $m < $sCount; $m++) {
                     $color = Color_handler::get_next($m);
                     $rgb = $color->get_rgb();
                     $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']);
                 }
             }
             $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 0, 0, 0, TRUE, 0, 0, TRUE);
             $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription());
         } else {
             $sCount = count($finalData['data']);
             if ($sCount > 0) {
                 for ($m = 0; $m < $sCount; $m++) {
                     $color = Color_handler::get_next($m % 3);
                     $rgb = $color->get_rgb();
                     $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']);
                 }
             }
             $Test->setLineStyle(2);
             $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 0, 0, 0, TRUE, 0, 2);
             $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
             $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2);
         }
         // Finish the graph
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 10);
         $imgName = uniqid('graph_') . '.png';
         $Test->Render($path . $imgName);
         return upload_to_amazon_graphImage($imgName, $path);
     }
 }
Ejemplo n.º 4
0
 function showGraph($searchInfo = '')
 {
     $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . intval($searchInfo['keywordId']);
     $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . intval($searchInfo['seId']);
     $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se  \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= " . intval($searchInfo['fromTime']) . " and time<" . intval($searchInfo['toTime']) . " {$conditions}  \r\n\t\t\t\t\torder by s.time";
     $repList = $this->db->select($sql);
     $reportList = array();
     $seList = array();
     foreach ($repList as $repInfo) {
         $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time'];
         if (empty($reportList[$var])) {
             $reportList[$var] = $repInfo;
         } else {
             if ($repInfo['rank'] < $reportList[$var]['rank']) {
                 $reportList[$var] = $repInfo;
             }
         }
         if (empty($seList[$repInfo['searchengine_id']])) {
             $seList[$repInfo['searchengine_id']] = $repInfo['domain'];
         }
     }
     asort($seList);
     $dataList = array();
     $maxValue = 0;
     foreach ($reportList as $repInfo) {
         $seId = $repInfo['searchengine_id'];
         $dataList[$repInfo['time']][$seId] = $repInfo['rank'];
         $maxValue = $repInfo['rank'] > $maxValue ? $repInfo['rank'] : $maxValue;
     }
     // check whether the records are available for drawing graph
     if (empty($dataList) || empty($maxValue)) {
         $kpText = $_SESSION['lang_code'] == 'ja' ? $_SESSION['text']['common']['No Records Found'] . "!" : "No Records Found!";
         $this->showMessageAsImage($kpText);
     }
     # Dataset definition
     $dataSet = new pData();
     foreach ($dataList as $dataInfo) {
         $i = 1;
         foreach ($seList as $seId => $seVal) {
             $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId];
             $dataSet->AddPoint($val, "Serie" . $i++);
         }
     }
     $i = 1;
     foreach ($seList as $seDomain) {
         $dataSet->AddSerie("Serie{$i}");
         $dataSet->SetSerieName($seDomain, "Serie{$i}");
         $i++;
     }
     $serieCount = count($seList) + 1;
     $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}");
     $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}");
     # if language is japanese
     if ($_SESSION['lang_code'] == 'ja') {
         $fontFile = "fonts/M+1P+IPAG.ttf";
         $dataSet->SetXAxisName($_SESSION['text']['common']["Date"]);
         $dataSet->SetYAxisName($_SESSION['text']['common']["Rank"]);
     } else {
         $fontFile = "fonts/tahoma.ttf";
         $dataSet->SetXAxisName("Date");
         $dataSet->SetYAxisName("Rank");
     }
     $dataSet->SetXAxisFormat("date");
     # Initialise the graph
     $chart = new pChart(720, 520);
     $chart->setFixedScale($maxValue, 1);
     $chart->setFontProperties($fontFile, 8);
     $chart->setGraphArea(85, 30, 670, 425);
     $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240);
     $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230);
     $chart->drawGraphArea(255, 255, 255, TRUE);
     $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2);
     $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
     # Draw the 0 line
     $chart->setFontProperties($fontFile, 6);
     $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
     # Draw the line graph
     $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription());
     $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255);
     $j = 1;
     $chart->setFontProperties($fontFile, 10);
     foreach ($seList as $seDomain) {
         $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++);
     }
     # Finish the graph
     $chart->setFontProperties("fonts/tahoma.ttf", 8);
     $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255);
     $chart->setFontProperties($fontFile, 10);
     $kpText = $_SESSION['lang_code'] == 'ja' ? $this->spTextKeyword["Keyword Position Report"] : "Keyword Position Report";
     $chart->drawTitle(60, 22, $kpText, 50, 50, 50, 585);
     $chart->stroke();
 }
Ejemplo n.º 5
0
 function main()
 {
     $ThisArea = array('1' => 'Orizaba', '2' => 'Guadalajara', '3' => 'Ramos Arizpe', '4' => 'Tijuana');
     if (!$this->args) {
         $this->help();
         $this->err(__('Usage report <year> <area> <month> <fraction> <all_areas> ', true));
         $this->_stop();
     }
     $KmsConditions = null;
     if (isset($this->args[0]) && !isset($this->args[3])) {
         $CurrentYear = $this->args[0];
         $KmsConditions['KmsCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "%";
     }
     if (isset($this->args[1])) {
         $KeyArea = $this->args[1];
         $KmsConditions['KmsCurrent.id_area'] = $KeyArea;
     } else {
         $KeyArea = null;
     }
     if (isset($this->args[2])) {
         $CurrentMonth = $this->args[2];
         $CurrentYear = $this->args[0];
         $KmsConditions['KmsCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "-" . $CurrentMonth . "%";
     } else {
         $CurrentMonth = null;
     }
     if (isset($this->args[3])) {
         $Fraccion = $this->args[3];
         $KmsConditions['KmsCurrent.id_fraccion'] = $Fraccion;
     } else {
         $Fraccion = null;
     }
     if (isset($this->args[4])) {
         $all = $this->args[4];
     } else {
         $all = null;
     }
     $args = $this->args;
     /** ALERT Like in the ancient times Define the vars firts
      **/
     //       $KmsConditions = null;
     //       $this->out(pr($KmsConditions));
     //       $this->out(pr($args));exit();
     $NumDays = date('t', mktime('0', '0', '0', $CurrentMonth, '01', $CurrentYear));
     /** TODO => Firts we need all areas => all fractions => CurrentYear
     **	 => Second Detail By Four Areas => CurrentYear
     **	 => Third Graphics by Area => Month => Fraction => CurrentYear
     **/
     $kms_full = $full = $kms_all = null;
     $kms_search = $this->KmsCurrent->find('all', array('conditions' => $KmsConditions));
     //       $this->out(pr($KmsConditions));
     //       $this->out(pr($kms_search));
     //       exit();
     if (!empty($kms_search)) {
         foreach ($kms_search as $key => $value) {
             if ($value['KmsCurrent']['id_configuracionviaje'] == '3') {
                 $kms_full[$value['KmsCurrent']['no_viaje']][] = $value['KmsCurrent']['kms_viaje'];
                 $kms_full[$value['KmsCurrent']['no_viaje']]['day'] = substr($value['KmsCurrent']['fecha_guia'], 8, 2);
             } elseif ($value['KmsCurrent']['id_configuracionviaje'] == '2' or $value['KmsCurrent']['id_configuracionviaje'] == '1') {
                 $kms_all += $value['KmsCurrent']['kms_viaje'];
                 $kms_senc[substr($value['KmsCurrent']['fecha_guia'], 8, 2)] = $value['KmsCurrent']['kms_viaje'];
             }
         }
         foreach ($kms_full as $k => $data) {
             $full += $data['0'];
             $full_days[$data['day']] += $data['0'];
         }
         $AreaCorp['kms_all'] = ($kms_all + $full) * 2;
         $all_days = ($kms_all + array_sum($full_days)) * 2;
     } else {
         $AreaCorp['kms_all'] = null;
     }
     //       $this->out(pr($full));
     $this->out(pr($full_days));
     //       $this->out(array_sum($full_days));
     $this->out(pr($kms_senc));
     $this->out(pr($AreaCorp));
     $this->out(pr($all_days));
     //       exit();
     $report_day = $kms_senc;
     $report_year = array();
     /** ALERT Save the result for Display in the view
      */
     //2
     $this->autoRender = false;
     //3
     App::import('Vendor', 'pData', array('file' => 'pchart' . DS . 'pData.class'));
     App::import('Vendor', 'pChart', array('file' => 'pchart' . DS . 'pChart.class'));
     //4
     $fontFolder = APP . 'vendors' . DS . 'pchart' . DS . 'Fonts';
     $fontFolder = '..' . DS . '..' . DS . 'vendors' . DS . 'pchart' . DS . 'Fonts';
     //5
     // Dataset definition
     $DataSet = new pData();
     $MaxKms = max($report_day);
     $MaxKms = $MaxKms + 100;
     foreach ($report_day as $key => $value) {
         $MyDay[] = (int) $key;
     }
     // 	$this->out(pr($MyDay));
     $DataSet->AddPoint($report_day, "Serie1");
     // 	$DataSet->AddPoint('4',"Serie2");
     // 	$DataSet->AddPoint('20',"Serie3");
     // 	$DataSet->AddPoint($MyDay,"Name");
     // exit();
     //         $this->out(pr($DataSet->GetData()));
     // 	$idx=0;
     //         foreach($MyDay as $key => $value){
     // 	  $DataSet->AddPoint($value,"Serie1");
     // 	  $DataSet->AddPoint((int)$key,"Name");
     //         }
     // 	    $this->out(pr($MyDay));
     //         $DataSet->GetData()['0']['Name']=;
     // 	  $DataSet->GetData()['0']['Name']=1;
     $this->out(pr($DataSet->GetData()));
     $DataSet->AddAllSeries();
     $DataSet->SetAbsciseLabelSerie();
     $key = $value = null;
     $DataSet->SetSerieName("Kilometros", "Serie1");
     $DataSet->SetSerieName("Dia", "Serie2");
     $DataSet->SetYAxisName("Kilometros Dias");
     $DataSet->SetYAxisUnit("Kms");
     $DataSet->SetXAxisName("Dias");
     $DataSet->SetXAxisFormat("number");
     // Initialise the graph
     //          pr($SchemaFolder);
     $Test = new pChart(820, 260);
     $Test->setFixedScale(1, $MaxKms, 5, 0, $NumDays, 5);
     $Test->setDateFormat("H:m");
     $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10);
     // 	$Test->setColorPalette(0,115,173,207);
     // 	$Test->setColorPalette(1,144,196,226);
     $Test->setColorPalette(2, 174, 216, 240);
     $Test->setColorPalette(3, 64, 140, 195);
     $Test->setColorPalette(4, 104, 188, 209);
     $Test->setColorPalette(5, 99, 200, 226);
     $Test->setColorPalette(6, 82, 124, 148);
     $Test->setColorPalette(7, 97, 152, 183);
     $Test->setColorPalette(8, 105, 210, 231);
     $Test->setColorPalette(9, 167, 219, 216);
     $Test->setColorPalette(10, 224, 228, 204);
     $Test->setColorPalette(11, 243, 134, 48);
     // 	$Test->loadColorPalette("/tmp/schema/blue.txt",",");
     $Test->setGraphArea(100, 30, 790, 200);
     //       $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
     $Test->drawRoundedRectangle(5, 5, 810, 225, 5, 230, 230, 230);
     $Test->drawGraphArea(255, 255, 255, TRUE);
     // 	dibujar la grafica
     $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE);
     $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
     // Draw the line graph
     // Draw the 0 line
     $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10);
     $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
     // Draw the bar graph
     $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80);
     //  $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription());
     //     $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2");
     //     $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie3");
     //     $Test->drawXYGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2");
     // Finish the graph
     $today = date('Y-m-d');
     // 	$Test->setFontProperties($fontFolder.DS."tahoma.ttf",8);
     //  	$Test->drawLegend(820,150,$DataSet->GetDataDescription(),255,255,255);
     $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10);
     // 	$_today =
     if (isset($KeyArea)) {
         $area = "_" . $KeyArea;
     } else {
         $area = "_0";
     }
     if (isset($Fraccion)) {
         $fraction = "_" . $Fraccion;
     } else {
         $fraction = "_0";
     }
     $Test->drawTitle(220, 22, "Kilometros {$ThisArea[$KeyArea]} {$MyMonth} {$CurrentYear}", 50, 50, 50, 585);
     $Test->Render("../../app/webroot/img/thumbs/graph_kms_" . $today . $area . $fraction . ".png");
 }
Ejemplo n.º 6
0
 function showGraph($searchInfo = '')
 {
     $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . $searchInfo['keywordId'];
     $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . $searchInfo['seId'];
     $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se  \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= {$searchInfo['fromTime']} and time<{$searchInfo['toTime']} {$conditions}  \r\n\t\t\t\t\torder by s.time";
     $repList = $this->db->select($sql);
     $reportList = array();
     $seList = array();
     foreach ($repList as $repInfo) {
         $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time'];
         if (empty($reportList[$var])) {
             $reportList[$var] = $repInfo;
         } else {
             if ($repInfo['rank'] < $reportList[$var]['rank']) {
                 $reportList[$var] = $repInfo;
             }
         }
         if (empty($seList[$repInfo['searchengine_id']])) {
             $seList[$repInfo['searchengine_id']] = $repInfo['domain'];
         }
     }
     asort($seList);
     $dataList = array();
     foreach ($reportList as $repInfo) {
         $seId = $repInfo['searchengine_id'];
         $dataList[$repInfo['time']][$seId] = $repInfo['rank'];
     }
     # Dataset definition
     $dataSet = new pData();
     foreach ($dataList as $dataInfo) {
         $i = 1;
         foreach ($seList as $seId => $seVal) {
             $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId];
             $dataSet->AddPoint($val, "Serie" . $i++);
         }
     }
     $i = 1;
     foreach ($seList as $seDomain) {
         $dataSet->AddSerie("Serie{$i}");
         $dataSet->SetSerieName($seDomain, "Serie{$i}");
         $i++;
     }
     $serieCount = count($seList) + 1;
     $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}");
     $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}");
     $dataSet->SetXAxisName("Date");
     $dataSet->SetYAxisName("Rank");
     $dataSet->SetXAxisFormat("date");
     # Initialise the graph
     $chart = new pChart(720, 520);
     $chart->setFontProperties("fonts/tahoma.ttf", 8);
     $chart->setGraphArea(85, 30, 670, 425);
     $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240);
     $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230);
     $chart->drawGraphArea(255, 255, 255, TRUE);
     $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2);
     $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
     # Draw the 0 line
     $chart->setFontProperties("fonts/tahoma.ttf", 6);
     $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
     # Draw the line graph
     $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription());
     $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255);
     $j = 1;
     $chart->setFontProperties("fonts/tahoma.ttf", 10);
     foreach ($seList as $seDomain) {
         $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++);
     }
     # Finish the graph
     $chart->setFontProperties("fonts/tahoma.ttf", 8);
     $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255);
     $chart->setFontProperties("fonts/tahoma.ttf", 10);
     $chart->drawTitle(60, 22, "Keyword Position Report", 50, 50, 50, 585);
     $chart->stroke();
 }
Ejemplo n.º 7
0
function stacked2($data, $title, $filename)
{
    // Dataset definition
    $DataSet = new pData();
    $values = $data['values'];
    $keys = $data['keys'];
    $bar = new pChart(1040, 230);
    for ($i = 0; $i < count($values); $i++) {
        $DataSet->AddPoint($values[$i], "Serie" . ($i + 1));
        if ($i != 0) {
            $DataSet->AddSerie("Serie" . ($i + 1));
            $DataSet->SetSerieName($keys[$i - 1], "Serie" . ($i + 1));
        }
    }
    $DataSet->SetAbsciseLabelSerie("Serie1");
    $DataSet->SetXAxisFormat("date");
    // Initialise the graph
    $bar->setDateFormat("M.d");
    $bar->setFontProperties("Fonts/consola.ttf", 8);
    $bar->setGraphArea(80, 30, 1020, 200);
    $bar->drawFilledRoundedRectangle(2, 2, 1037, 227, 5, 240, 240, 240);
    $bar->drawRoundedRectangle(0, 0, 1039, 229, 5, 230, 230, 230);
    $bar->loadColorPalette('chartcolors.txt', ',');
    $bar->drawGraphArea(255, 255, 255, TRUE);
    $bar->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, 0, 2, TRUE);
    $bar->drawGrid(4, TRUE, 230, 230, 230, 50);
    // Draw the 0 line
    $bar->setFontProperties("Fonts/consola.ttf", 6);
    $bar->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
    // Draw the bar graph
    $bar->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 100);
    $bar->drawLegend(85, 35, $DataSet->GetDataDescription(), 255, 255, 255);
    // Finish the graph
    $bar->setFontProperties("Fonts/MankSans.ttf", 10);
    $bar->drawTitle(10, 20, $title, 100, 100, 100);
    $bar->Render($filename);
}
Ejemplo n.º 8
0
 function main()
 {
     $ThisArea = array('1' => 'Orizaba', '2' => 'Guadalajara', '3' => 'Ramos Arizpe', '4' => 'Tijuana');
     if (!$this->args) {
         $this->help();
         $this->err(__('Usage report <id_area> <id_fraccion> <year> <month> <all_areas> ', true));
         $this->_stop();
     }
     $KeyArea = $this->args[0];
     $Fraccion = $this->args[1];
     $CurrentYear = $this->args[2];
     $CurrentMonth = $this->args[3];
     $all = $this->args[4];
     $args = $this->args;
     $this->out(pr($args));
     $NumDays = date('t', mktime('0', '0', '0', $CurrentMonth, '01', $CurrentYear));
     if (empty($all) && !empty($KeyArea) && !empty($CurrentMonth)) {
         // CurrentMonth Area
         $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "-" . $CurrentMonth . "%";
         $TonelajeConditions['TonelajeCurrent.id_area'] = $KeyArea;
         $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion;
     }
     if ($all == true && $KeyArea == false && $CurrentMonth == false) {
         // AllYear
         $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "%";
         $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion;
     }
     if ($all == true && $KeyArea > 0 && $CurrentMonth == false) {
         // AllYearArea
         $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%" . $CurrentYear . "%";
         $TonelajeConditions['TonelajeCurrent.id_area'] = $KeyArea;
         $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion;
     }
     //       $this->out(pr($TonelajeConditions));exit();
     //       $TonelajeConditions['TonelajeCurrent.fecha_guia LIKE'] = "%".$CurrentYear."-".$CurrentMonth."%";
     //       $TonelajeConditions['TonelajeCurrent.id_area'] = $KeyArea;
     //       $TonelajeConditions['TonelajeCurrent.id_fraccion'] = $Fraccion;
     //       $this->out(pr($TonelajeConditions));exit();
     $report = $this->TonelajeCurrent->find('all', array('conditions' => $TonelajeConditions));
     $toneladas = null;
     $report_day = array();
     $report_year = array();
     //     $this->out(pr($report));exit();
     foreach ($report as $key => $data) {
         if ($data['TonelajeCurrent']['status_guia'] == ' B') {
             $canceladas[] = $data;
         }
         $MyMonth = date('M', mktime('0', '0', '0', $CurrentMonth, '01', $CurrentYear));
         // 	    $this->out(pr($data));
         // 	    $report_day['00'] = '0';
         if ($data['TonelajeCurrent']['status_guia'] !== ' B') {
             $toneladas += $data['TonelajeCurrent']['peso'];
             $counter[] = $data['TonelajeCurrent']['peso'];
             $day = substr($data['TonelajeCurrent']['fecha_guia'], 8, 2);
             $report_day[$day] += $data['TonelajeCurrent']['peso'];
         }
     }
     // End foreach $report
     /** ALERT Save the result for Display in the view
      */
     //       $this->out(pr($report_day));exit();
     //       $this->out($NumDays);
     //       $this->out($MyMonth);
     //       exit();
     //       $this->out(count($counter));exit();
     //2
     $this->autoRender = false;
     //3
     App::import('Vendor', 'pData', array('file' => 'pchart' . DS . 'pData.class'));
     App::import('Vendor', 'pChart', array('file' => 'pchart' . DS . 'pChart.class'));
     //4
     $fontFolder = APP . 'vendors' . DS . 'pchart' . DS . 'Fonts';
     $fontFolder = '..' . DS . '..' . DS . 'vendors' . DS . 'pchart' . DS . 'Fonts';
     //          $SchemaFolder = APP.'vendors'.DS.'pchart'.DS.'schema';
     //5
     // Dataset definition
     $DataSet = new pData();
     $MaxTons = max($report_day);
     $MaxTons = $MaxTons + 100;
     foreach ($report_day as $key => $value) {
         $MyDay[] = (int) $key;
     }
     // 	$this->out(pr($MyDay));
     $DataSet->AddPoint($report_day, "Serie1");
     // 	$DataSet->AddPoint('4',"Serie2");
     // 	$DataSet->AddPoint('20',"Serie3");
     // 	$DataSet->AddPoint($MyDay,"Name");
     // exit();
     //         $this->out(pr($DataSet->GetData()));
     // 	$idx=0;
     //         foreach($MyDay as $key => $value){
     // 	  $DataSet->AddPoint($value,"Serie1");
     // 	  $DataSet->AddPoint((int)$key,"Name");
     //         }
     // 	    $this->out(pr($MyDay));
     //         $DataSet->GetData()['0']['Name']=;
     // 	  $DataSet->GetData()['0']['Name']=1;
     $this->out(pr($DataSet->GetData()));
     $DataSet->AddAllSeries();
     $DataSet->SetAbsciseLabelSerie();
     $key = $value = null;
     $DataSet->SetSerieName("Toneladas", "Serie1");
     $DataSet->SetSerieName("Dia", "Serie2");
     $DataSet->SetYAxisName("Toneladas Dias");
     $DataSet->SetYAxisUnit("Ton");
     $DataSet->SetXAxisName("Dias");
     $DataSet->SetXAxisFormat("number");
     // Initialise the graph
     //          pr($SchemaFolder);
     $Test = new pChart(820, 260);
     $Test->setFixedScale(1, $MaxTons, 5, 0, $NumDays, 5);
     $Test->setDateFormat("H:m");
     $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10);
     $Test->setColorPalette(0, 115, 173, 207);
     $Test->setColorPalette(1, 144, 196, 226);
     $Test->setColorPalette(2, 174, 216, 240);
     $Test->setColorPalette(3, 64, 140, 195);
     $Test->setColorPalette(4, 104, 188, 209);
     $Test->setColorPalette(5, 99, 200, 226);
     $Test->setColorPalette(6, 82, 124, 148);
     $Test->setColorPalette(7, 97, 152, 183);
     $Test->setColorPalette(8, 105, 210, 231);
     $Test->setColorPalette(9, 167, 219, 216);
     $Test->setColorPalette(10, 224, 228, 204);
     $Test->setColorPalette(11, 243, 134, 48);
     // 	$Test->loadColorPalette("/tmp/schema/blue.txt",",");
     $Test->setGraphArea(100, 30, 790, 200);
     //       $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
     $Test->drawRoundedRectangle(5, 5, 810, 225, 5, 230, 230, 230);
     $Test->drawGraphArea(255, 255, 255, TRUE);
     // 	dibujar la grafica
     $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE);
     $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
     // Draw the line graph
     // Draw the 0 line
     $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10);
     $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
     // Draw the bar graph
     $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE, 80);
     //  $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription());
     //     $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2");
     //     $Test->drawXYPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie3");
     //     $Test->drawXYGraph($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","Serie2");
     // Finish the graph
     $today = date('Y-m-d');
     // 	$Test->setFontProperties($fontFolder.DS."tahoma.ttf",8);
     //  	$Test->drawLegend(820,150,$DataSet->GetDataDescription(),255,255,255);
     $Test->setFontProperties($fontFolder . DS . "tahoma.ttf", 10);
     if (empty($all) && !empty($KeyArea) && !empty($CurrentMonth)) {
         // CurrentMonth Area
         $Test->drawTitle(220, 22, "Toneladas {$ThisArea[$KeyArea]} {$MyMonth} {$CurrentYear}", 50, 50, 50, 585);
         $Test->Render("../../app/webroot/img/thumbs/graph_" . $today . "_" . $KeyArea . "_" . $Fraccion . ".png");
     }
     if ($all == true && $KeyArea == false && $CurrentMonth == false) {
         // AllYear
         $Test->drawTitle(220, 22, "Toneladas {$CurrentYear}", 50, 50, 50, 585);
         $Test->Render("../../app/webroot/img/thumbs/graph_" . $CurrentYear . "_" . $KeyArea . ".png");
     }
     if ($all == true && $KeyArea > 0 && $CurrentMonth == false) {
         // AllYearArea
         $Test->drawTitle(220, 22, "Toneladas {$ThisArea[$KeyArea]} {$CurrentYear}", 50, 50, 50, 585);
         $Test->Render("../../app/webroot/img/thumbs/graph_" . $CurrentYear . "_" . $KeyArea . ".png");
     }
     // 	$Test->drawTitle(220,22,"Toneladas $MyMonth $CurrentYear",50,50,50,585);
     // 	$Test->Render("../../app/webroot/img/thumbs/graph_".$today."_".$KeyArea."_".$Fraccion.".png");
 }
Ejemplo n.º 9
0
        if ($i == 0) {
            $XAxis[] = date("H:i", $data_server[$i]);
        } else {
            $OLNum[] = $data_server[$i];
        }
    }
}
$pChartDataSet = new pData();
$pChartDataSet->AddPoint($XAxis, "Serie1");
$pChartDataSet->AddPoint($OLNum, "Serie2");
$pChartDataSet->AddSerie("Serie2");
$pChartDataSet->RemoveSerie("Serie1");
$pChartDataSet->SetAbsciseLabelSerie("Serie1");
$pChartDataSet->SetYAxisName("在\n线\n人\n数\n//\n人");
$pChartDataSet->SetYAxisFormat("floor");
$pChartDataSet->SetXAxisFormat("number");
// 设置作图区域
$pChartGraph = new pChart($imgWidth, 253);
$pChartGraph->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND);
$pChartGraph->setGraphArea(70, 30, $imgWidth + 70 - 90, 253 + 30 - 80);
$pChartGraph->setFontProperties(DRAWFONE_PATH, 8);
$pChartGraph->drawScale($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), SCALE_NORMAL, 250, 250, 250, TRUE, 0, 0, FALSE, 1);
// 开始作图
$pChartGraph->setColorPalette(0, 0, 255, 255);
$pChartGraph->drawGraphAreaGradient(40, 40, 40, -50);
$pChartGraph->drawGrid(1, TRUE, 115, 115, 115, 10);
$pChartGraph->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
$pChartGraph->drawFilledLineGraph($pChartDataSet->GetData(), $pChartDataSet->GetDataDescription(), 25);
$pChartGraph->clearShadow();
$pChartGraph->setFontProperties(DRAWFONE_PATH, 10);
$pChartGraph->drawTitle($imgWidth / 2, 22, "实时在线人数查询(" . $dateTime . ") 峰值( " . $maxNumberIndex . ", " . $maxNumber . "人 )", 255, 255, 255, 585);
Ejemplo n.º 10
-1
 function cartesianChart($type, $x, $y, $w, $h, $imgname = '', $config = array())
 {
     $w -= 4;
     $h -= 4;
     $settings = array('FontName' => 'tahoma.ttf', 'FontSize' => 8, 'LegendFontSize' => 8, 'LegendFontName' => 'tahoma.ttf', 'Logo' => '', 'LogoTransparency' => 20, 'XAxisFormat' => 'number', 'XAxisUnit' => '', 'YAxisFormat' => 'number', 'YAxisUnit' => '', 'XLogo' => 0, 'YLogo' => 0, 'Xlabel' => 'x label', 'XAngle' => 0, 'Ylabel' => 'y label', 'Legend' => '', 'Textbox' => '', 'TextboxFontSize' => 8, 'TextboxFontName' => 'tahoma.ttf', 'ImgR' => 132, 'ImgG' => 173, 'ImgB' => 131, 'Decay' => 80, 'BGR' => 163, 'BGG' => 203, 'BGB' => 167, 'Decay2' => 80, 'Filled' => '', 'DataR' => 191, 'DataG' => 120, 'DataB' => 71, 'LBR' => 226, 'LBG' => 228, 'LBB' => 230, 'LR' => 0, 'LG' => 0, 'LB' => 0);
     // Get the custom settings
     if (is_array($config)) {
         foreach ($config as $key => $val) {
             $settings[$key] = $val;
         }
     }
     $DataSet = new pData();
     $DataSet->AddPoint($y, "Serie1");
     $DataSet->AddPoint($x, "Serie2");
     $DataSet->AddAllSeries();
     $DataSet->RemoveSerie("Serie2");
     $DataSet->SetAbsciseLabelSerie("Serie2");
     $DataSet->SetSerieName($settings['Legend'], "Serie1");
     $DataSet->SetYAxisName($settings['Ylabel']);
     $DataSet->SetXAxisName($settings['Xlabel']);
     $DataSet->SetXAxisFormat($settings['XAxisFormat']);
     if (strlen($settings['XAxisUnit'])) {
         $DataSet->SetXAxisUnit($settings['XAxisUnit']);
     }
     if (strlen($settings['YAxisUnit'])) {
         $DataSet->SetYAxisUnit($settings['YAxisUnit']);
     }
     $DataSet->SetYAxisFormat($settings['YAxisFormat']);
     // Initialise the graph
     $Test = new pChart($w, $h);
     $Test->drawGraphAreaGradient($settings['ImgR'], $settings['ImgG'], $settings['ImgB'], $settings['Decay'], TARGET_BACKGROUND);
     $FontSize = $settings['FontSize'];
     $FontName = $this->_ext_path . "/fonts/" . $settings['FontName'];
     $Test->setFontProperties($FontName, $FontSize);
     //Calc Textbox Height
     if (strlen($settings['Textbox'])) {
         $TextboxFontSize = $settings['TextboxFontSize'];
         $TextboxFontName = $this->_ext_path . "/fonts/" . $settings['TextboxFontName'];
         $Position = imageftbbox($TextboxFontSize, 0, $TextboxFontName, $settings['Textbox']);
         $TextboxHeight = $Position[1] - $Position[7] + 8;
     } else {
         $TextboxHeight = 0;
     }
     // Maximize The graph area
     //on Y axis
     if ($settings['XAxisFormat'] == 'time') {
         $xdata = "99:99:99";
         $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
         $WXmax = $Position[2] - $Position[0];
         $TextHeightX = $Position[1] - $Position[7];
     } elseif ($settings['XAxisFormat'] == 'date') {
         $xdata = "99/99/9999";
         $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
         $WXmax = $Position[2] - $Position[0];
         $TextHeightX = $Position[1] - $Position[7];
     } else {
         $WXmax = 0;
         foreach ($x as $xdata) {
             $xdata .= $settings['XAxisUnit'];
             $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
             $TextWidth = $Position[2] - $Position[0];
             $TextHeightX = $Position[1] - $Position[7];
             $WXmax = $TextWidth > $WXmax ? $TextWidth : $WXmax;
         }
     }
     if ($settings['XAngle'] > 0) {
         $sin = abs(sin(deg2rad($settings['XAngle'])));
         $cos = abs(cos(deg2rad($settings['XAngle'])));
         $HXmax = $WXmax * $sin + $TextHeightX * $cos;
     } else {
         $HXmax = $TextHeightX;
     }
     //on Y axis...
     if ($settings['YAxisFormat'] == 'time') {
         $ydata = "99:99:99";
         $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
         $WYmax = $Position[2] - $Position[0];
         $TextHeightY = $Position[1] - $Position[7];
     } elseif ($settings['YAxisFormat'] == 'date') {
         $ydata = "99/99/9999";
         $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
         $WYmax = $Position[2] - $Position[0];
         $TextHeightY = $Position[1] - $Position[7];
     } else {
         $WYmax = 0;
         foreach ($y as $ydata) {
             $ydata .= $settings['YAxisUnit'];
             //echo $ydata."<br>";
             $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
             $TextWidth = $Position[2] - $Position[0];
             $TextHeightY = $Position[1] - $Position[7];
             $WYmax = $TextWidth > $WYmax ? $TextWidth : $WYmax;
         }
     }
     $Test->setGraphArea($WYmax + $TextHeightY + 35, 20, $w - 25, $h - $HXmax - $TextHeightX - $TextboxHeight - 20);
     //$Test->setGraphArea(60,20,$w-25,($settings['XAngle']==0)?$h-70:$h-100);
     $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, $settings['XAngle'], 0, TRUE);
     $Test->drawGraphAreaGradient($settings['BGR'], $settings['BGG'], $settings['BGB'], $settings['Decay2']);
     $Test->drawGrid(4, TRUE, 230, 230, 230, 20);
     // This will put the picture "logo.png" with transparency
     if (strlen($settings['Logo'])) {
         $XLogo = $WYmax + $TextHeightY + 35 + $settings['XLogo'];
         $YLogo = 20 + $settings['XLogo'];
         $logo = $settings['Logo'];
         //Fing extension of logo : png,gif or jpg
         if ($this->_findexts($logo) == "png") {
             echo "png!";
             $Test->drawFromPNG($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         } elseif ($this->_findexts($logo) == "gif") {
             echo "gif!";
             $Test->drawFromGIF($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         } elseif ($this->_findexts($logo) == "jpg") {
             echo "jpg";
             $Test->drawFromJPG($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         }
     }
     $Test->setColorPalette(0, $settings['DataR'], $settings['DataG'], $settings['DataB']);
     if ($type == "bar") {
         // Draw the bar chart
         $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70);
     } elseif ($type == "line") {
         $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
     } elseif ($type == "cubic") {
         $Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
         $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
         $Test->clearShadow();
         if ($settings['Filled'] == 'yes') {
             $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30);
         }
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
     }
     // Draw the textbox
     if (strlen($settings['Textbox'])) {
         $Test->setFontProperties($TextboxFontName, $TextboxFontSize);
         $Test->drawTextBox(0, $h - $TextboxHeight, $w, $h, $settings['Textbox'], 0, 255, 255, 255, ALIGN_CENTER, TRUE, 0, 0, 0, 30);
     }
     // Draw the legend
     if (strlen($settings['Legend'])) {
         $LegendFontSize = $settings['LegendFontSize'];
         $LegendFontName = $this->_ext_path . "/fonts/" . $settings['LegendFontName'];
         $Position = imageftbbox($LegendFontSize, 0, $LegendFontName, $settings['Legend']);
         $LegendW = $Position[2] - $Position[0] + 40;
         $Test->setFontProperties($LegendFontName, $LegendFontSize);
         $Test->drawLegend($w - $LegendW, 10, $DataSet->GetDataDescription(), $settings['LBR'], $settings['LBG'], $settings['LBB'], 52, 58, 82, $settings['LR'], $settings['LG'], $settings['LB'], TRUE);
     }
     // Render the picture
     $Test->addBorder(2);
     if (strlen($imgname)) {
         //custom image name
         $imgname = $this->_img_path . "/" . $imgname;
     } else {
         $this->obj->load->helper('string');
         $imgname = $this->_img_path . "/{$type}-" . random_string('alnum', 16) . ".png";
     }
     $Test->Render($imgname);
     return array("name" => '/' . $imgname, "w" => $w + 4, "h" => $h + 4);
 }