/**
  * Render graph
  *
  *@return nothing
  **/
 function render($p_stack = FALSE)
 {
     // declare the graph
     $Test = new pChart(800, 250);
     $Test->tmpFolder = $this->tmpPath;
     $fileId = time() . '_' . rand(1, 1000);
     $fontFile = "tahoma.ttf";
     // prepare the map
     echo '<SCRIPT TYPE="text/javascript" SRC="' . $this->pChartPath . 'overlib.js"></SCRIPT>
   <SCRIPT TYPE="text/javascript" SRC="' . $this->pChartPath . 'pMap.js"></SCRIPT>';
     $MapID = "map_" . $fileId . ".map";
     $Test->setImageMap(TRUE, $MapID);
     $Map = new pChart(800, 250);
     $Map->tmpFolder = $this->tmpPath;
     $imgName = "img_" . $fileId . ".png";
     $img = $this->tmpPath . $imgName;
     $imgLink = GLPI_ROOT . "/plugins/fusioninventory/front/send.php?file=" . urlencode("tmp/" . $imgName);
     $mapLink = GLPI_ROOT . "/plugins/fusioninventory/front/send.php?file=" . urlencode("tmp/" . $MapID);
     echo '<DIV ID="overDiv" STYLE="position:absolute; visibility:hidden; z-index:1000;"></DIV>';
     echo "<IMG ID='fusioninventory_graph_{$fileId}' SRC='{$imgLink}' WIDTH=800 HEIGHT=250 BORDER=0 OnMouseMove='fusioninventory_graph(event);' OnMouseOut='nd();'>";
     echo '<SCRIPT>
           function fusioninventory_graph(event) {
              LoadImageMap("fusioninventory_graph_' . $fileId . '","' . $mapLink . '");
              getMousePosition(event);
           }
         </SCRIPT>';
     // configure the graph
     $Test->setFontProperties($this->fontsPath . $fontFile, 8);
     $Test->setGraphArea(80, 30, 580, 185);
     // graph size : keep place for titles on X and Y axes
     $Test->drawFilledRoundedRectangle(7, 7, 793, 243, 5, 240, 240, 240);
     // background rectangle
     $Test->drawRoundedRectangle(5, 5, 795, 245, 5, 230, 230, 230);
     // 3D effect
     $Test->drawGraphArea(255, 255, 255, TRUE);
     $Test->setFixedScale(0, $this->getMaxY($this->maxValue), $this->divisionsY);
     // to see values from 0
     $Test->drawScale($this->pData->GetData(), $this->pData->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, 0, 2, TRUE);
     $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
     // Draw the 0 line
     $Test->setFontProperties($this->fontsPath . $fontFile, 6);
     // Draw the bar graph
     if ($p_stack) {
         $Test->drawStackedBarGraph($this->pData->GetData(), $this->pData->GetDataDescription(), 100);
     } else {
         $Test->drawBarGraph($this->pData->GetData(), $this->pData->GetDataDescription(), FALSE, 100);
     }
     // Finish the graph
     $Test->setFontProperties($this->fontsPath . $fontFile, 8);
     $Test->drawLegend(590, 30, $this->pData->GetDataDescription(), 255, 255, 255);
     // take care of legend text size
     $Test->setFontProperties($this->fontsPath . $fontFile, 10);
     $Test->drawTitle(50, 22, $this->title . ' (/ ' . $this->timeUnitName . ')', 50, 50, 50, 585);
     $Test->Render($img);
 }
Esempio n. 2
0
        $data[$s['day']] = $s['u_pro'];
    }
}
// Standard inclusions
include 'pChart/pData.class';
include 'pChart/pChart.class';
// Dataset definition
$DataSet = new pData();
$DataSet->AddPoint($data, 'S1');
$DataSet->AddPoint(array_keys($data), 'S2');
$DataSet->AddSerie('S1');
$DataSet->SetAbsciseLabelSerie('S2');
// Initialise the graph
$Test = new pChart(700, 230);
if ($is_null) {
    $Test->setFixedScale(0, 1, 1);
}
$Test->setFontProperties('Fonts/tahoma.ttf', 8);
$Test->setGraphArea(50, 30, 665, 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 cubic curve graph
$Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
// Finish the graph
$Test->setFontProperties('Fonts/tahoma.ttf', 10);
$Test->drawTitle(50, 22, 'Пользователи PRO', 50, 50, 50, 585);
$Test->Stroke();
?>
 public function componentLineGraph()
 {
     $DataSet = new pData();
     $maxvals = array();
     foreach ($this->datasets as $ds_id => $dataset) {
         $DataSet->AddPoint($dataset['values'], "Serie" . $ds_id, array_keys($dataset['values']));
         $maxvals[] = max($dataset['values']);
         if (isset($dataset['burndown'])) {
             $amount = count($dataset['values']) > 1 ? $dataset['burndown']['maxEstimation'] / (count($dataset['values']) - 1) : 0;
             for ($i = 0; $i < count($dataset['values']); $i++) {
                 $burndownValues[] = $dataset['burndown']['maxEstimation'] - $i * $amount;
             }
             $DataSet->AddPoint($burndownValues, "Burndown" . $ds_id, $dataset['burndown']['maxEstimation']);
         }
     }
     $DataSet->AddAllSeries();
     if (isset($this->labels)) {
         $DataSet->AddPoint($this->labels, "Labels");
         $DataSet->SetAbsciseLabelSerie("Labels");
     } else {
         $DataSet->SetAbsciseLabelSerie();
     }
     foreach ($this->datasets as $ds_id => $dataset) {
         $DataSet->SetSerieName($dataset['label'], "Serie" . $ds_id);
         if (isset($dataset['burndown'])) {
             $DataSet->SetSerieName($dataset['burndown']['label'], "Burndown" . $ds_id);
         }
     }
     if (isset($this->values_title)) {
         $DataSet->SetYAxisName($this->values_title);
     }
     if (isset($this->labels_title)) {
         $DataSet->SetXAxisName($this->labels_title);
     }
     // Initialise the graph
     $Test = new pChart($this->width, $this->height);
     $Test->setFixedScale(0, ceil(max($maxvals) / 5) * 5);
     $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8);
     if (isset($this->labels_title)) {
         $Test->setGraphArea(50, 30, $this->width - 30, $this->height - 45);
     } else {
         $Test->setGraphArea(50, 30, $this->width - 30, $this->height - 30);
     }
     $Test->drawFilledRoundedRectangle(2, 2, $this->width - 3, $this->height - 3, 5, 240, 240, 240);
     $Test->drawRoundedRectangle(0, 0, $this->width - 1, $this->height - 1, 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(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 6);
     $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
     // Draw the cubic curve graph
     if (isset($this->style) && $this->style == 'curved') {
         $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
     } elseif (isset($this->style) && $this->style == 'filled_line') {
         $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, true);
     } elseif (isset($this->style) && $this->style == 'stacked_bar') {
         $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 50, true);
     } elseif (isset($this->style) && $this->style == 'single_bar') {
         $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE);
     } else {
         $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
     }
     if (isset($this->include_plotter) && $this->include_plotter) {
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
     }
     // Finish the graph
     $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSans.ttf', 8);
     //$Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255);
     $Test->drawLegend(55, 35, $DataSet->GetDataDescription(), 255, 255, 255);
     $Test->setFontProperties(THEBUGGENIE_MODULES_PATH . 'pchart' . DS . 'fonts' . DS . 'DroidSansBold.ttf', 10);
     $Test->drawTitle(50, 22, $this->title, 50, 50, 50, $this->width - 30);
     $Test->Stroke();
     //("example2.png");
 }
 // Initialise the graph   
 $Test = new pChart(700,400);   
 $Test->setFontProperties("../lib/Fonts/tahoma.ttf",8);   
 $Test->setGraphArea(50,30,670,370);   
 $Test->drawFilledRoundedRectangle(5,5,695,395,5,191,191,191);
 /*
 $Test->drawRoundedRectangle(0,0,700,400,5,33,33,33);
 $Test->drawRoundedRectangle(1,1,699,399,5,33,33,33);
 $Test->drawRoundedRectangle(2,2,698,398,5,33,33,33);
 $Test->drawRoundedRectangle(3,3,697,397,5,33,33,33);   
 */
 $Test->drawGraphArea(150,150,150); 
 
 $nb_joueurs_graph = ($nb_joueurs - $nb_joueurs % 10) + 10;
 
 $Test->setFixedScale($nb_joueurs_graph,0,$nb_joueurs_graph/5,0,38,1);
 $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,20,20,20,TRUE,0,2);   
 $Test->drawGrid(4,FALSE,0,0,0);
 
 // Draw the 0 line   
 $Test->setFontProperties("../lib/Fonts/tahoma.ttf",6);   
 $Test->drawTreshold(0,143,55,72,TRUE,TRUE);   
 
 // Draw the line graph
 //$Test->setLineStyle(3);
 $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());   
 $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),2,0,255,0,0);   
 //$Test->writeValues($DataSet->GetData(),$DataSet->GetDataDescription(),"SerieClassement");
 
 // Finish the graph   
 $Test->setFontProperties("../lib/Fonts/tahoma.ttf",8);   
Esempio n. 5
0
    Example2 : A cubic curve graph
*/
// Standard inclusions
include "../lib/pData.php";
include "../lib/pChart.php";
// Dataset definition
$DataSet = new pData();
$DataSet->AddPoint(array(1, 4, 3, 4, 3, 3, 2, 1, 0, 7, 4, 3, 2, 3, 3, 5, 1, 0, 7), "Serie1");
$DataSet->AddPoint(array(1, 4, 2, 6, 2, 3, 0, 1, 5, 1, 2, 4, 5, 2, 1, 0, 6, 4, 2), "Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January", "Serie1");
$DataSet->SetSerieName("February", "Serie2");
// Initialise the graph
$Test = new pChart(700, 230);
$Test->setFixedScale(-2, 8);
$Test->setFontProperties("../Fonts/tahoma.ttf", 8);
$Test->setGraphArea(50, 30, 585, 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 cubic curve graph
$Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
// Finish the graph
$Test->setFontProperties("../Fonts/tahoma.ttf", 8);
$Test->drawLegend(600, 30, $DataSet->GetDataDescription(), 255, 255, 255);
Esempio n. 6
0
    /**
     * Generates an histogram
     *
     * @param 	array	list of exercise names
     * @param 	array	my results 0 to 100
     * @param 	array	average scores 0-100
     */
    static function generate_session_exercise_graph($names, $my_results, $average)
    {
        require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
        require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
        require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';

        $cache = new pCache();

        // Dataset definition
        $data_set = new pData();

        // Dataset definition
        $data_set->AddPoint($average,	 "Serie1");
        $data_set->AddPoint($my_results, "Serie2");
        $data_set->AddPoint($names,		 "Serie3");
        $data_set->AddAllSeries();
        $data_set->SetAbsciseLabelSerie('Serie3');
        $data_set->SetSerieName(get_lang('AverageScore'),"Serie1");
        $data_set->SetSerieName(get_lang('MyResults'),	 "Serie2");

        //$data_set->SetYAxisName(get_lang("Percentage"));

        $data_set->SetYAxisUnit("%");

        // Initialise the graph
        $main_width    = 860;
        $main_height   = 500;
        $y_label_angle = 50;
        $data_set->RemoveSerie("Serie3");
        $graph = new pChart($main_width, $main_height);
        //See 3.2 BT#2797
        $graph->setFixedScale(0,100);

        $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
        $graph->setGraphArea(65,50,$main_width-20, $main_height-140);

        $graph->drawFilledRoundedRectangle(7,7,$main_width-7,$main_height-7,5,240,240,240);
        $graph->drawRoundedRectangle(5,5,$main_width-5,$main_height -5,5,230,230,230);
        $graph->drawGraphArea(255,255,255,TRUE);

        //SCALE_NORMAL, SCALE_START0, SCALE_ADDALLSTART0, SCALE_ADDALL
        $graph->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_NORMAL ,150,150,150,TRUE,$y_label_angle,1, TRUE);
        $graph->drawGrid(4,TRUE,230,230,230,70);

        // Draw the 0 line
        $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6);
        $graph->drawTreshold(0,143,55,72,TRUE,TRUE);

        // Draw the cubic curve graph
        $graph->drawLineGraph($data_set->GetData(),$data_set->GetDataDescription());
        $graph->drawPlotGraph($data_set->GetData(),$data_set->GetDataDescription(),1,1,230,255,255);

        // Finish the graph
        $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
        $graph->drawLegend($main_width - 150,70,$data_set->GetDataDescription(),255,255,255);

        $graph->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',11);
        $graph->drawTitle(50, 30, get_lang('ExercisesInTimeProgressChart'), 50,50,50,$main_width-110, true);

        // $main_graph = new pChart($main_width,$main_height);
        $courseCode = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : null;
        $graph_id = 'generate_session_exercise_graph'.$courseCode.'-'.intval($_GET['session_id']).'-'.api_get_user_id();
        if ($cache->IsInCache($graph_id, $data_set->GetData())) {
        //if (0) {
            //if we already created the img
            //echo 'in cache';
            $img_file = $cache->GetHash($graph_id,$data_set->GetData());
        } else {
            $cache->WriteToCache($graph_id, $data_set->GetData(), $graph);
            ob_start();
            $graph->Stroke();
            ob_end_clean();
            $img_file = $cache->GetHash($graph_id, $data_set->GetData());
        }
        $html = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
        return $html;
    }
	/**
 	 * This method return a graph containing information about evaluations
     * inside courses in sessions, it's used inside get_block method for
     * showing it inside dashboard interface
 	 * @return string  img html
 	 */
    public function get_evaluations_courses_in_sessions_graph()
    {
		$graphs = array();
		if (!empty($this->sessions)) {
			$session_ids = array_keys($this->sessions);
			foreach ($session_ids as $session_id) {
				$courses_code = array_keys(Tracking::get_courses_list_from_session($session_id));
				$courses_graph = array();
				foreach ($courses_code as $course_code) {
					$cats = Category::load(null, null, $course_code, null, null, $session_id);
					if (isset($cats) && isset($cats[0])) {
						$alleval = $cats[0]->get_evaluations(null, true, $course_code);
						$alllinks = $cats[0]->get_links(null, true);
						$users = get_all_users($alleval, $alllinks);
						$datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks);
						$evaluation_sumary = $datagen->get_evaluation_sumary_results();
						if (!empty($evaluation_sumary)) {
							$items = array_keys($evaluation_sumary);
							$max = $min = $avg = array();
							foreach ($evaluation_sumary as $evaluation) {
								$max[] = $evaluation['max'];
								$min[] = $evaluation['min'];
								$avg[] = $evaluation['avg'];
							}
							// Dataset definition
						    $data_set = new pData;
						    $data_set->AddPoint($max, "Max");
						    $data_set->AddPoint($avg, "Avg");
						    $data_set->AddPoint($min, "Min");
						    $data_set->AddPoint($items, "Items");
						    $data_set->SetXAxisName(get_lang('EvaluationName'));
							$data_set->SetYAxisName(get_lang('Percentage'));
							$data_set->AddAllSeries();
						   	$data_set->RemoveSerie("Items");
						   	$data_set->SetAbsciseLabelSerie("Items");
						    $graph_id = $this->user_id.'StudentEvaluationGraph';
							$cache = new pCache();
							// the graph id
							$data = $data_set->GetData();
							if ($cache->IsInCache($graph_id, $data)) {
								//if we already created the img
								$img_file = $cache->GetHash($graph_id, $data);
							} else {
								// Initialise the graph
                                $angle = -30;
							    $test = new pChart($this->bg_width, $this->bg_height);
							    $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8);
                                $test->fixHeightByRotation(
                                    $data_set->GetData(),
                                    $data_set->GetDataDescription(),
                                    $angle
                                );
                                $test->setGraphArea(50, 30, $this->bg_width - 75, $this->bg_height - 75);
                                $test->drawFilledRoundedRectangle(
                                    7,
                                    7,
                                    $this->bg_width - 20,
                                    $test->YSize - 20,
                                    5,
                                    240,
                                    240,
                                    240
                                );
                                $test->drawRoundedRectangle(
                                    5,
                                    5,
                                    $this->bg_width - 18,
                                    $test->YSize - 18,
                                    5,
                                    230,
                                    230,
                                    230
                                );
							    $test->drawGraphArea(255,255,255,TRUE);
							    $test->setFixedScale(0,100,5);
                                $test->drawScale(
                                    $data_set->GetData(),
                                    $data_set->GetDataDescription(),
                                    SCALE_ADDALL,
                                    150,
                                    150,
                                    150,
                                    TRUE,
                                    $angle,
                                    2,
                                    TRUE
                                );
							    $test->setColorPalette(0,105,221,34);
								$test->setColorPalette(1,255,135,30);
								$test->setColorPalette(2,255,0,0);
							    $test->drawGrid(4,TRUE,230,230,230,50);
							    // Draw the 0 line
							    $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',6);
							    $test->drawTreshold(0,143,55,72,TRUE,TRUE);
							    // Draw the bar graph
							    $test->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription(), 100);
							    // Finish the graph
							    $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
							    $test->drawLegend($this->bg_width-80,20,$data_set->GetDataDescription(),255,255,255);
							    $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
							    $test->setColorPalette(0,50,50,50);
								$test->setColorPalette(1,50,50,50);
								$test->setColorPalette(2,50,50,50);
							    $test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),array("Min", "Max", "Avg"));
							    $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
								ob_start();
								$test->Stroke();
								ob_end_clean();
								$img_file = $cache->GetHash($graph_id, $data_set->GetData());
							}
							if (!empty($img_file)) {
								$courses_graph[$course_code] = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
							}
						}
					}
				}
				if (!empty($courses_graph)) {
					$graphs[$session_id] = $courses_graph;
				}
			}
		}
    	return $graphs;
 	}
     $DataSet->AddAllSeries("Serie{$key}");
     $lastid = $key;
 }
 if (!empty($abciselabel)) {
     $nk = $lastid + 1;
     $DataSet->AddPoint($abciselabel, "Serie{$nk}");
     $DataSet->SetAbsciseLabelSerie("Serie{$nk}");
 } else {
     $DataSet->SetAbsciseLabelSerie();
 }
 foreach ($series as $key => $val) {
     $DataSet->SetSerieName($val['name'], "Serie{$key}");
 }
 // Initialise the graph
 $Test = new pChart(700, 230);
 $Test->setFixedScale($min, $max);
 $Test->setFontProperties($CFG->dirroot . "/report/configreports/lib/Fonts/tahoma.ttf", 8);
 $Test->setGraphArea(70, 30, 680, 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($CFG->dirroot . "/report/configreports/lib/Fonts/tahoma.ttf", 10);
 $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);
 // Finish the graph
 $Test->setFontProperties($CFG->dirroot . "/report/configreports/lib/Fonts/tahoma.ttf", 8);
 // Build Chart
 $Test = new pChart(600, 280);
 $Test->loadColorPalette("pChart/hardtones.pal");
 // Make Evenly Disable Ranks (No Real Numbers) - optimizing by making sure $max is not prime
 $max = max($max_rank);
 $max = $max + (7 - $max % 7);
 for ($divs = 5; ($max - 1) % $divs != 0 && $max % $divs != 0; $divs += 1) {
 }
 if ($max % $divs == 0) {
     $max = $max + 1;
 }
 if ($divs > 15) {
     $divs = 15;
 }
 // Set Y Scale
 $Test->setFixedScale($max, 1, $divs, 0, 0, 1);
 // Draw Graph Area
 $Test->setFontProperties("Fonts/tahoma.ttf", 10);
 $Test->setGraphArea(45, 30, 450, 200);
 $Test->drawGraphArea(255, 255, 255, TRUE);
 $Test->setFontProperties("Fonts/tahoma.ttf", 8);
 // Scale grid and background
 $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 80, 80, 80, TRUE, 50, 100, FALSE, $time_label_hours);
 $Test->drawGrid(4, FALSE, 210, 210, 210);
 // Draw Data
 $Test->drawTreshold(1, 100, 100, 100);
 $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
 //$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription(),1);
 // Draw Legend
 $Test->drawLegend(465, 75, $DataSet->GetDataDescription(), 225, 225, 225, 0, 0, 0, 100, 100, 100, FALSE);
 // Draw Title
$DataSet->SetSerieName("Kerosene", "Serie3");
$DataSet->SetYAxisName("Amount Used (kg)");
$DataSet->SetXAxisName("Month of the year");
$DataSet->SetSerieSymbol("Serie1", "../Sample/Point_Asterisk.gif");
$DataSet->SetSerieSymbol("Serie2", "../Sample/Point_Cd.gif");
// Initialise the graph
$Test = new pChart(890, 250);
$Test->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND);
$Test->setGraphArea(60, 40, 595, 190);
//$RectangleSettings = array("R"=>209,"G"=>31,"B"=>27,"Alpha"=>50,"Surrounding"=>30);
//$Test->drawRoundedFilledRectangle(10,25,70,55,5,$RectangleSettings);
//$RectangleSettings = array("R"=>209,"G"=>31,"B"=>27,"Alpha"=>50,"Surrounding"=>30);
//$Test->drawGraphAreaGradient(132,173,131,50, TARGET_BACKGROUND);
//$Test->drawGraphAreaGradient(132,173,131,50, $RectangleSettings);
$Test->reportWarnings("GD");
$Test->setFixedScale(0, 18, 5);
$Test->setFontProperties("../Fonts/tahoma.ttf", 8);
//$Test->setGraphArea(65, 30, 570, 185);
//$Test->drawFilledRoundedRectangle(7, 7, 800, 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, 0, 0, 0, TRUE, 0, 2, TRUE, 1);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 213, 217, 221, TRUE, 0, 0);
//$Test->drawGraphAreaGradient(162, 183, 202, 50);
$Test->drawGraphAreaGradient(40, 40, 40, -50);
//$Test->drawGrid(4, TRUE, 230, 230, 230, 20);
$Test->drawGrid(4, TRUE, 230, 230, 230, 10);
$Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->clearShadow();
$Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30);
//$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
Esempio n. 11
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");
 }
Esempio n. 12
0
 public function build()
 {
     require_once PCHART_BASE_DIR . DIRECTORY_SEPARATOR . 'pData.php';
     require_once PCHART_BASE_DIR . DIRECTORY_SEPARATOR . 'pChart.php';
     $dataSet = new pData();
     foreach ($this->lines as $name => $ordinateValues) {
         if (count($ordinateValues) != count($this->absciseValues)) {
             throw new Exception('Count of line "' . $name . '" ordinate points "' . count($ordinateValues) . '" mismatch to abscise points "' . count($this->absciseValues) . '"');
         }
         $dataSet->AddPoint($ordinateValues, $name);
     }
     $dataSet->AddPoint($this->absciseValues, 'Abscise');
     $dataSet->AddAllSeries();
     $dataSet->RemoveSerie('Abscise');
     $dataSet->SetAbsciseLabelSerie('Abscise');
     foreach ($this->lines as $name => $ordinateValues) {
         $dataSet->SetSerieName($name, $name);
     }
     $dataSet->SetYAxisUnit($this->ordinateStepTitle);
     $dataSet->SetXAxisUnit($this->absciseStepTitle);
     $chart = new pChart($this->maxWidth, $this->maxHeight);
     $chart->drawGraphAreaGradient(132, 153, 172, 50, TARGET_BACKGROUND);
     // Graph area setup
     $chart->setFontProperties(PCHART_FONTS_DIR . DIRECTORY_SEPARATOR . 'tahoma.ttf', 10);
     $chart->setGraphArea($this->graphMargins[0], $this->graphMargins[1], $this->maxWidth - $this->graphMargins[2], $this->maxHeight - $this->graphMargins[3]);
     $chart->drawGraphArea(213, 217, 221, FALSE);
     $ordinateScaleMargin = ($this->getMaxOrdinateValue() - $this->getMinOrdinateValue()) / $this->ordinateDevisions;
     $chart->setFixedScale($this->getMinOrdinateValue() - $ordinateScaleMargin, $this->getMaxOrdinateValue() + $ordinateScaleMargin, $this->ordinateDevisions);
     $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 213, 217, 221, TRUE, 0, 2);
     $chart->drawGraphAreaGradient(162, 183, 202, 50);
     $chart->drawGrid(4, TRUE, 230, 230, 230, 20);
     // Draw the line chart
     //		$chart->setShadowProperties(1, 1, 0, 0, 0, 30, 4);
     $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription());
     $chart->clearShadow();
     $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 5, 3, -1, -1, -1, TRUE);
     // Draw the legend
     $chart->drawLegend($this->maxWidth - $this->graphMargins[2] + 10, $this->graphMargins[1], $dataSet->GetDataDescription(), 236, 238, 240, 52, 58, 82);
     // Draw chart title
     if ($this->chartTitle) {
         $chart->drawTextBox(0, $this->maxHeight - 20, $this->maxWidth, $this->maxHeight, $this->chartTitle, 0, 255, 255, 255, ALIGN_RIGHT, TRUE, 0, 0, 0, 30);
     }
     // Render the picture
     $chart->addBorder(2);
     $chart->Render($this->outputFilepath);
 }
Esempio n. 13
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");
 }
}
while ($rowHistoJournees = mysql_fetch_array($resultHistoJournees)) {
    $tabVals[$rowHistoJournees[0]] = $rowHistoJournees[1];
}
$dataSet->AddPoint($tabVals, "Serie1");
$dataSet->AddPoint($tabDays, "Serie2");
$dataSet->AddSerie("Serie1");
$dataSet->SetAbsciseLabelSerie("Serie2");
// Graph width
$width = 800;
// Graph height
$height = 230;
$heightForAngle = 0;
$absLabelAngle = 0;
// Initialize the graph
$chart = new pChart($width, $height + $heightForAngle);
$chart->setGraphArea(40, 30, $width - 20, $height - 30);
$chart->setFontProperties("../lib/Fonts/tahoma.ttf", 10);
$chart->drawFilledRoundedRectangle(7, 7, $width - 7, $height - 7 + $heightForAngle, 5, 240, 240, 240);
$chart->drawRoundedRectangle(5, 5, $width - 5, $height - 5 + $heightForAngle, 5, 230, 230, 230);
$chart->drawGraphArea(252, 252, 252);
// definition of drawScale method : drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
$chart->setFixedScale(0, 10);
$chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, $absLabelAngle, 2, TRUE);
$chart->drawGrid(4, TRUE, 230, 230, 230, 255);
// Draw the bar graph
$chart->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), TRUE);
// Finish the graph
$chart->setFontProperties("../lib/Fonts/tahoma.ttf", 10);
$chart->drawTitle(0, 0, "", 50, 50, 50, $width, 35);
$chart->Stroke();
$DataSet->AddPoint($x_lable_arr, "x_lable_name");
$DataSet->SetAbsciseLabelSerie("x_lable_name");
$DataSet->AddAllSeries();
$DataSet->RemoveSerie("x_lable_name");
$DataSet->SetSerieName("", "Serie3");
// $DataSet->SetYAxisName("Kg");
// $DataSet->SetXAxisName("week");
$DataSet->SetSerieSymbol("Serie3", $normal_circle);
$DataSet->SetSerieSymbolLastOne("Serie3", $last_circle);
// Initialise the graph
$Test = new pChart($width, $height);
$Test->setFontPropertiesDir("{$pChart_dir}/Fonts");
// Add an image
$Test->drawFromPNG($background, 0, 0);
$Test->reportWarnings("GD");
$Test->setFixedScale($min_y_value, $max_y_value, 5);
$Test->setFontProperties("{$pChart_dir}/Fonts/tahoma.ttf", 14);
$Test->setGraphArea($area_margin_left, 20, $width - 30, $height - 55);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 255, 255, 255, TRUE, 0, 2, TRUE, 1);
$Test->drawGrid(4, TRUE, 233, 218, 213, 0);
//画网格
// Draw the area
$Test->drawArea($DataSet->GetData(), "Serie3", "Serie4", 239, 238, 227, 40);
$DataSet->RemoveSerie("Serie4");
// Draw the line graph
$Test->setColorPalette(0, 255, 237, 237);
$Test->setLineStyle(2, 0);
//设置虚线的宽度
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->setColorPalette(0, 243, 247, 252);
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 5, 3, 255, 255, 255);
Esempio n. 16
0
$DataSet->SetYAxisUnit(" min");
$DataSet->SetXAxisUnit("h");
// Initialise the graph
$Test = new pChart(800, 230);
/* $Test->setColorPalette(0,155,206,240); 
 $Test->setColorPalette(1,107,183,233); 
 $Test->setColorPalette(2,81,170,230); 
 $Test->setColorPalette(3,46,151,224); 
*/
$Test->drawGraphAreaGradient(230, 230, 230, 50, TARGET_BACKGROUND);
// $Test->loadColorPalette("pChart/tones-8.txt");
//$Test->createColorGradientPalette(10,194,251,23,20,151,5);
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->setGraphArea(80, 20, 775, 190);
$Test->drawGraphArea(180, 190, 210, TRUE);
$Test->setFixedScale(0, 60, 6);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 100, 100, 100, TRUE, 0, 2, TRUE);
//$Test->drawGraphAreaGradient(150,150,150,80);
// $Test->drawGraphAreaGradient(163,203,167,50);
$Test->drawGrid(2, TRUE, 230, 230, 230, 40);
// Draw the bar chart
// Draw the title
// $Title = "  Average Temperatures during\r\n  the first months of 2008  ";
// $Test->drawTextBox(0,0,50,230,$Title,90,255,255,255,ALIGN_BOTTOM_CENTER,TRUE,0,0,0,30);
$Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 60);
// Draw the legend
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->drawLegend(690, 10, $DataSet->GetDataDescription(), 186, 188, 220, 52, 58, 82);
// Render the picture
$Test->addBorder(2);
$Test->Stroke();
Esempio n. 17
0
$DataSet = new pData();
// $DataSet->AddPoint(array(10,9.4,7.7,5,1.7,-1.7,-5,-7.7,-9.4,-10,-9.4,-7.7,-5,-1.8,1.7),"Serie1");
// $DataSet->AddPoint(array(0,3.4,6.4,8.7,9.8,9.8,8.7,6.4,3.4,0,-3.4,-6.4,-8.6,-9.8,-9.9),"Serie2");
$DataSet->AddPoint(array(7.1, 9.1, 10, 9.699999999999999, 8.199999999999999, 5.7, 2.6, -0.9, -4.2, -7.1, -9.1, -10, -9.699999999999999, -8.199999999999999, -5.8), "Serie3");
// $DataSet->AddPoint(array("Jan","Jan","Jan","Feb","Feb","Feb","Mar","Mar","Mar","Apr","Apr","Apr","May","May","May"),"Serie4");
$DataSet->AddAllSeries();
// $DataSet->SetAbsciseLabelSerie("Serie4");
// $DataSet->SetSerieName("Max Average","Serie1");
// $DataSet->SetSerieName("Min Average","Serie2");
$DataSet->SetSerieName("Temperature", "Serie3");
$DataSet->SetYAxisName("Kg");
$DataSet->SetXAxisName("week");
// Initialise the graph
$Test = new pChart(600, 230);
$Test->reportWarnings("GD");
$Test->setFixedScale(-12, 13, 5);
//
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->setGraphArea(65, 20, 570, 185);
$Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 243, 249, 249);
$Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
$Test->drawGraphArea(243, 249, 249, TRUE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 3);
$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 area
// $DataSet->RemoveSerie("Serie4");
// $Test->drawArea($DataSet->GetData(),"Serie1","Serie2",239,238,227,50);
// $DataSet->RemoveSerie("Serie3");
Esempio n. 18
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();
 }
Esempio n. 19
0
 public function testDrawArea()
 {
     // Dataset definition
     $DataSet = new pData();
     $DataSet->addPoints(array(10, 9.4, 7.7, 5, 1.7, -1.7, -5, -7.7, -9.4, -10, -9.4, -7.7, -5, -1.8, 1.7), "Serie1");
     $DataSet->addPoints(array(0, 3.4, 6.4, 8.699999999999999, 9.800000000000001, 9.800000000000001, 8.699999999999999, 6.4, 3.4, 0, -3.4, -6.4, -8.6, -9.800000000000001, -9.9), "Serie2");
     $DataSet->addPoints(array(7.1, 9.1, 10, 9.699999999999999, 8.199999999999999, 5.7, 2.6, -0.9, -4.2, -7.1, -9.1, -10, -9.699999999999999, -8.199999999999999, -5.8), "Serie3");
     $DataSet->addPoints(array("Jan", "Jan", "Jan", "Feb", "Feb", "Feb", "Mar", "Mar", "Mar", "Apr", "Apr", "Apr", "May", "May", "May"), "Serie4");
     $DataSet->AddAllSeries();
     $DataSet->SetAbscissaLabelSeries("Serie4");
     $DataSet->SetSeriesName("Max Average", "Serie1");
     $DataSet->SetSeriesName("Min Average", "Serie2");
     $DataSet->SetSeriesName("Temperature", "Serie3");
     $DataSet->SetYAxisName("Temperature");
     $DataSet->SetXAxisName("Month of the year");
     // Initialise the graph
     $canvas = new TestCanvas();
     $Test = new pChart(700, 230, $canvas);
     $Test->reportWarnings("GD");
     $Test->setFixedScale(-12, 12, 5);
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->setGraphArea(65, 30, 570, 185);
     $canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
     $backgroundStyle = new BackgroundStyle(new Color(255), TRUE);
     $Test->drawGraphBackground($backgroundStyle);
     $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(150));
     $Test->drawScale($DataSet, $scaleStyle, 0, 2, TRUE, 3);
     $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 50));
     // Draw the 0 line
     $Test->setFontProperties("Fonts/tahoma.ttf", 6);
     $Test->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
     // Draw the area
     $DataSet->RemoveSeries("Serie4");
     $Test->drawArea($DataSet->GetData(), "Serie1", "Serie2", new Color(239, 238, 227), 50);
     $DataSet->RemoveSeries("Serie3");
     $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
     // Draw the line graph
     $Test->setLineStyle(1, 6);
     $DataSet->RemoveAllSeries();
     $DataSet->AddSeries("Serie3");
     $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
     $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, new Color(255));
     // Write values on Serie3
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie3");
     // Finish the graph
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->drawLegend(590, 90, $DataSet->GetDataDescription(), new Color(255));
     $Test->setFontProperties("Fonts/tahoma.ttf", 10);
     $Test->drawTitle(60, 22, "example 15", new Color(50), 585);
     // Add an image
     $Test->drawFromPNG(dirname(__FILE__) . "/../Sample/logo.png", 584, 35);
     $this->assertEquals('53b34d556af518230b7556e19349bd94', md5($canvas->getActionLog()));
 }
Esempio n. 20
0
$DataSet = new pData();
$DataSet->AddPoint(array(9, 9, 9, 10, 10, 11, 12, 14, 16, 17, 18, 18, 19, 19, 18, 15, 12, 10, 9), "Serie1");
$DataSet->AddPoint(array(10, 11, 11, 12, 12, 13, 14, 15, 17, 19, 22, 24, 23, 23, 22, 20, 18, 16, 14), "Serie2");
$DataSet->AddPoint(array(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22), "Serie3");
$DataSet->AddAllSeries();
$DataSet->RemoveSerie("Serie3");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("January", "Serie1");
$DataSet->SetSerieName("February", "Serie2");
$DataSet->SetYAxisName("Temperature");
$DataSet->SetYAxisUnit("°C");
$DataSet->SetXAxisUnit("h");
// Initialise the graph
$Test = new pChart(700, 230);
$Test->drawGraphAreaGradient(90, 90, 90, 90, TARGET_BACKGROUND);
$Test->setFixedScale(0, 40, 4);
// Graph area setup
$Test->setFontProperties("../Fonts/pf_arma_five.ttf", 6);
$Test->setGraphArea(60, 40, 680, 200);
$Test->drawGraphArea(200, 200, 200, FALSE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 200, 200, 200, TRUE, 0, 2);
$Test->drawGraphAreaGradient(40, 40, 40, -50);
$Test->drawGrid(4, TRUE, 230, 230, 230, 10);
// Draw the line chart
$Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
$Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->clearShadow();
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
// Write the title
$Test->setFontProperties("../Fonts/MankSans.ttf", 18);
$Test->setShadowProperties(1, 1, 0, 0, 0);
 function display_graph_by_resource()
 {
     require_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php';
     require_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php';
     require_once api_get_path(LIBRARY_PATH) . 'pchart/pCache.class.php';
     $header_name = $this->datagen->get_header_names();
     $total_users = $this->datagen->get_total_users_count();
     $img_file = '';
     if ($this->datagen->get_total_items_count() > 0 && $total_users > 0) {
         //Removing first name
         array_shift($header_name);
         //Removing last name
         array_shift($header_name);
         $displayscore = ScoreDisplay::instance();
         $customdisplays = $displayscore->get_custom_score_display_settings();
         if (is_array($customdisplays) && count($customdisplays)) {
             $user_results = $this->datagen->get_data_to_graph2();
             $pre_result = $new_result = array();
             $DataSet = new pData();
             //filling the Dataset
             foreach ($user_results as $result) {
                 //print_r($result);
                 for ($i = 0; $i < count($header_name); $i++) {
                     $pre_result[$i + 3][] = $result[$i + 1];
                 }
             }
             $i = 0;
             $show_draw = false;
             $resource_list = array();
             $pre_result2 = array();
             foreach ($pre_result as $key => $res_array) {
                 rsort($res_array);
                 $pre_result2[] = $res_array;
             }
             //@todo when a display custom does not exist the order of the color does not match
             //filling all the answer that are not responded with 0
             rsort($customdisplays);
             if ($total_users > 0) {
                 foreach ($pre_result2 as $key => $res_array) {
                     $key_list = array();
                     foreach ($res_array as $user_result) {
                         $resource_list[$key][$user_result[1]] += 1;
                         $key_list[] = $user_result[1];
                     }
                     foreach ($customdisplays as $display) {
                         if (!in_array($display['display'], $key_list)) {
                             $resource_list[$key][$display['display']] = 0;
                         }
                     }
                     $i++;
                 }
             }
             //fixing $resource_list
             $max = 0;
             $new_list = array();
             foreach ($resource_list as $key => $value) {
                 $new_value = array();
                 foreach ($customdisplays as $item) {
                     if ($value[$item['display']] > $max) {
                         $max = $value[$item['display']];
                     }
                     $new_value[$item['display']] = strip_tags($value[$item['display']]);
                 }
                 $new_list[] = $new_value;
             }
             $resource_list = $new_list;
             $i = 1;
             $j = 0;
             foreach ($resource_list as $key => $resource) {
                 $new_resource_list = $new_resource_list_name = array();
                 $DataSet = new pData();
                 // Reverse array, otherwise we get highest values first
                 $resource = array_reverse($resource, true);
                 foreach ($resource as $name => $cant) {
                     $DataSet->AddPoint($cant, "Serie" . $j);
                     $DataSet->SetSerieName(strip_tags($name), "Serie" . $j);
                     $j++;
                 }
                 //print_r($pre_result); print_r($header_name);
                 // Dataset definition
                 $DataSet->AddAllSeries();
                 $DataSet->SetAbsciseLabelSerie('');
                 $DataSet->SetXAxisName(get_lang('GradebookSkillsRanking'));
                 $DataSet->SetYAxisName(get_lang('Students'));
                 $show_draw = true;
                 // Cache definition
                 $Cache = new pCache();
                 // the graph id
                 $gradebook_id = intval($_GET['selectcat']);
                 $graph_id = api_get_user_id() . 'ByResource' . $gradebook_id . api_get_course_id() . api_get_session_id();
                 if ($show_draw) {
                     //if ($Cache->IsInCache($graph_id, $DataSet->GetData())) {
                     if (0) {
                         //if we already created the img we get the img file id
                         //echo 'in cache';
                         $img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
                     } else {
                         // if the image does not exist in the archive/ folder
                         // Initialise the graph
                         $chart_size_w = 480;
                         $chart_size_h = 250;
                         $Test = new pChart($chart_size_w, $chart_size_h);
                         // Adding the color schemma
                         $Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/pastel.txt");
                         // set font of the axes
                         $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8);
                         $area_graph_w = $chart_size_w - 130;
                         $Test->setGraphArea(50, 30, $area_graph_w, $chart_size_h - 50);
                         $Test->drawFilledRoundedRectangle(5, 5, $chart_size_w - 1, $chart_size_h - 20, 5, 240, 240, 240);
                         //$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230);
                         //background color area & stripe or not
                         $Test->drawGraphArea(255, 255, 255, TRUE);
                         //Setting max height by default see #3296
                         if (!empty($max)) {
                             $Test->setFixedScale(0, $max);
                         }
                         $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 0, FALSE);
                         //background grid
                         $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
                         // Draw the 0 line
                         //$Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",6);
                         //$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
                         // Draw the bar graph
                         $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE);
                         //Set legend properties: width, height and text color and font
                         $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 9);
                         $Test->drawLegend($area_graph_w + 10, 50, $DataSet->GetDataDescription(), 255, 255, 255);
                         //Set title properties
                         $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 10);
                         $Test->drawTitle(50, 22, strip_tags($header_name[$i - 1]), 50, 50, 80, $chart_size_w - 50);
                         //------------------
                         //echo 'not in cache';
                         $Cache->WriteToCache($graph_id, $DataSet->GetData(), $Test);
                         //ob_start();
                         //$Test->Stroke();
                         //ob_end_clean();
                         $img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
                     }
                     echo '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '" >';
                     if ($i % 2 == 0 && $i != 0) {
                         echo '<br />';
                     }
                     $i++;
                 }
             }
             //end foreach
         } else {
             echo get_lang('ToViewGraphScoreRuleMustBeEnabled');
         }
         // Pie charts
         /*
         $show_draw = false;
         $resource_list = array();
         //print_r($pre_result_pie);
         
         if ($total_users>0) {
             foreach($pre_result_pie as $key=>$res_array) {
                 //$resource_list
                 foreach($res_array as $user_result) {
                     $total+=  $user_result / ($total_users*100);
                 }
                 echo $total;
                 //echo $total =  $res / ($total_users*100);
                 echo '<br>';
                 //$DataSet->AddPoint($total,"Serie".$i);
                 //$DataSet->SetSerieName($header_name[$i-1],"Serie".$i);
         
             }
         }
         //here--------------
         foreach($resource_list as $key=>$resource) {
             $new_resource_list = $new_resource_list_name = array();
         
             foreach($resource as $name=>$cant) {
                 $new_resource_list[]=$cant;
                 $new_resource_list_name[]=$name;
             }
             //Pie chart
             $DataSet = new pData;
             $DataSet->AddPoint($new_resource_list,"Serie1");
             $DataSet->AddPoint($new_resource_list_name,"Serie2");
             $DataSet->AddAllSeries();
             $DataSet->SetAbsciseLabelSerie("Serie2");
         
             $Test = new pChart(400,300);
             $Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/soft_tones.txt");
             // background
             //$Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
             // border color
             $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);
         
             // This will draw a shadow under the pie chart
             //$Test->drawFilledCircle(122,102,70,200,200,200);
         
              //Draw the pie chart
             $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8);
         
             $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);
             $tmp_path = api_get_path(SYS_ARCHIVE_PATH);
         
             $Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218);
             $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
             $user_id = api_get_user_id();
             $img_file_generated_name = $key.uniqid('').'gradebook.png';
             $Test->Render($tmp_path.$img_file_generated_name);
             chmod($tmp_path.$img_file_generated_name, api_get_permissions_for_new_files());
         
             if ($i % 2 == 0 && $i!= 0) {
                 echo '<br>';
             }
             echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file_generated_name.'">';
         }
         */
     }
 }
Esempio n. 22
0
 /**
  * Build The Bar Gharph image with given params 
  * and store in upload/pChart directory.
  *
  * @param  array  $params    an assoc array of name/value pairs          
  * @return array  $filesPath created image files Path.
  *
  * @static
  */
 static function barGraph($params, $divisionWidth = 44)
 {
     if (empty($params)) {
         return;
     }
     //get the required directory path.
     $config =& CRM_Core_Config::singleton();
     //get the default currency.
     $currency = $config->defaultCurrency;
     $pChartPath = str_replace('templates', 'packages', $config->templateDir);
     $pChartPath .= 'pChart/Fonts/';
     $uploadDirURL = str_replace('persist/contribute/', 'upload/pChart/', $config->imageUploadURL);
     $uploadDirPath = $config->uploadDir . 'pChart/';
     //create pchart directory, if exist clean and then create again.
     if (is_dir($uploadDirPath)) {
         CRM_Utils_File::cleanDir($uploadDirPath);
         CRM_Utils_File::createDir($uploadDirPath);
     } else {
         CRM_Utils_File::createDir($uploadDirPath);
     }
     require_once 'packages/pChart/pData.class.php';
     require_once 'packages/pChart/pChart.class.php';
     $chartCount = 0;
     $filesValues = array();
     foreach ($params as $chartIndex => $chartValues) {
         $chartCount++;
         $shades = 0;
         $names = $values = array();
         foreach ($chartValues['values'] as $indexName => $indexValue) {
             $names[] = $indexName;
             $values[] = $indexValue;
             $shades++;
         }
         $legend = CRM_Utils_Array::value('legend', $chartValues);
         $xname = CRM_Utils_Array::value('xname', $chartValues);
         $yname = CRM_Utils_Array::value('yname', $chartValues);
         //calculate max scale for graph.
         $maxScale = ceil(max($values) * 1.1);
         $fontSize = 8;
         $angleOfIncline = 45;
         $monetaryformatting = true;
         require_once 'CRM/Utils/Money.php';
         $formatedMoney = CRM_Utils_Money::format(max($values));
         $positions = imageftbbox($fontSize, 0, $pChartPath . "tahoma.ttf", $formatedMoney);
         $scaleTextWidth = $positions[2] - $positions[0];
         //need to increase Ysize if we incline money value.
         $increaseYBy = 0;
         $inclinePositions = imageftbbox($fontSize, $angleOfIncline, $pChartPath . "tahoma.ttf", $formatedMoney);
         $inclineTextWidth = $inclinePositions[2] - $inclinePositions[0];
         if ($inclineTextWidth > $divisionWidth) {
             $increaseYBy = $inclineTextWidth / 2;
         }
         //Initialise the co-ordinates.
         $xComponent = 20;
         $yComponent = 35;
         $ySize = 300;
         //calculate coords.
         $x1 = $xComponent + $scaleTextWidth;
         $y1 = $yComponent + $increaseYBy;
         $ySize += $increaseYBy;
         $y2 = $ySize - $yComponent;
         //calculate x axis size as per number of months.
         $x2 = $xComponent + $divisionWidth + $scaleTextWidth + (count($chartValues['values']) - 1) * $divisionWidth;
         $xSize = $x2 + $xComponent;
         $dataSet = new pData();
         $dataSet->AddPoint($values, "Serie1");
         $dataSet->AddPoint($names, "Serie2");
         $dataSet->AddSerie("Serie1");
         $dataSet->SetAbsciseLabelSerie("Serie2");
         //Initialise the graph
         $chart = new pChart($xSize, $ySize);
         $chart->setFontProperties($pChartPath . "tahoma.ttf", $fontSize);
         $chart->setGraphArea($x1, $y1, $x2, $y2);
         //set the y axis scale.
         $chart->setFixedScale(0, $maxScale, 1);
         $chart->drawFilledRoundedRectangle(0, 0, $xSize, $ySize, 5, 240, 240, 240);
         $chart->drawRoundedRectangle(0, 0, $xSize, $ySize, 5, 230, 230, 230);
         $chart->drawGraphArea(255, 255, 255, TRUE);
         $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 1, FALSE, $divisionWidth, $monetaryformatting);
         $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
         //set colors.
         $chart->setColorShades($shades, self::$_colors);
         //Draw the bar chart
         $chart->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), TRUE, 80, true);
         //get the series values and write at top.
         $chart->setColorPalette(0, 0, 0, 255);
         $dataDesc = $dataSet->GetDataDescription();
         $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), $dataDesc['Values'], $monetaryformatting, $angleOfIncline);
         //Write the title
         if ($legend) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 10);
             $chart->drawTitle(10, 20, $legend, 50, 50, 50);
         }
         if ($xname) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 8);
             $chart->drawTitle(0, 90, $xname, 2, 0, 2);
         }
         if ($yname) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 8);
             $chart->drawTitle(40, 290, $yname, 2, 0, 20);
         }
         $fileName = "pChartByMonth{$chartCount}" . time() . '.png';
         $chart->Render($uploadDirPath . $fileName);
         //get the file path.
         $filesValues[$chartIndex]['file_name'] = $uploadDirURL . $fileName;
         //get the co-ordinates
         $coords = $chart->coordinates();
         //format the coordinates to make graph clickable.
         $position = 0;
         $chartCoords = array();
         foreach ($chartValues['values'] as $name => $value) {
             $chartCoords[$name] = implode(',', array($coords['xCoords'][$position], $coords['yCoords'][$position], $coords['xCoords'][$position] + $divisionWidth / 2, $y2));
             $position++;
         }
         $filesValues[$chartIndex]['coords'] = $chartCoords;
         //free the chart and data objects.
         unset($chart);
         unset($dataSet);
     }
     return $filesValues;
 }