/** * Генерация графика * @param DataSet $DataSet * @param String $GraphTitle * @param String $safeToFile */ function createGraphToFile($DataSet, $GraphTitle, $safeToFile, $scaleFormat) { // Rotrate $rotate = 30; // Initialise the graph $GraphImage = new pChart(594, 344); $GraphImage->setDateFormat($scaleFormat); // $GraphImage->loadColorPalette(DIR_FONT.'/tones-3.txt'); $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 8); $GraphImage->setGraphArea(80, 50, 580, 300); $GraphImage->drawFilledRectangle(3, 3, 590, 340, 240, 240, 240); $GraphImage->drawRectangle(0, 0, 593, 343, 230, 230, 230); $GraphImage->drawGraphArea(255, 255, 255, TRUE); $GraphImage->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, $rotate, 0, FALSE); $GraphImage->drawGrid(4, TRUE, 230, 230, 230, 50); // Draw the 0 line $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 6); $GraphImage->drawTreshold(0, 143, 55, 72, TRUE, TRUE); // Просто пунктирная линия // Draw the cubic curve graph $GraphImage->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription()); // Draw the line graph //$GraphImage->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); $GraphImage->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255); // Finish the graph $GraphImage->setFontProperties(DIR_FONT . "/segoepr.ttf", 12); $GraphImage->drawTitle(60, 32, $GraphTitle, 50, 50, 50, 600); //$GraphImage->Render(DIR_CACHE . './' . $safeToFile . '.png'); $GraphImage->Stroke(); }
$DataSet->AddPoint($points, "points"); $DataSet->AddPoint($rank, "rank"); $DataSet->AddPoint($time, "time"); $DataSet->AddSerie("points"); $DataSet->SetAbsciseLabelSerie(); $DataSet->SetSerieName("Punkte", "points"); $DataSet->SetSerieName("Rank", "rank"); $DataSet->SetYAxisName("Punkte"); $DataSet->SetAbsciseLabelSerie("time"); //$DataSet->SetXAxisFormat("date"); // Cache definition $Cache = new pCache('../charts/Cache/'); if ($use_cache && !$Cache->GetFromCache(md5($user['name']), $DataSet->GetData(), $FileName) or !$use_cache) { // Initialise the graph $Test = new pChart(715, 230); $Test->setDateFormat('d.m H:i'); $Test->setFontProperties("../charts/Fonts/tahoma.ttf", 8); $Test->setGraphArea(60, 30, 650, 150); $Test->drawFilledRoundedRectangle(7, 7, 708, 223, 5, 240, 240, 240); $Test->drawRoundedRectangle(5, 5, 710, 225, 5, 163, 203, 167); $Test->drawGraphArea(255, 255, 255, TRUE); $Test->drawGraphAreaGradient(163, 203, 167, 50); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_DIFF, 150, 150, 150, TRUE, 75, 0, FALSE, $skip_scale); $Test->drawGrid(4, TRUE, 230, 230, 230, 40); // Draw the graph $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30); if ($scale_hours <= 48) { $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2, 1, 255, 255, 255); } // Draw labels if (!empty($ccities)) {
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"); }
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); }
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"); }