コード例 #1
0
 /**
  * This method return a graph containing informations about students evaluation, it's used inside get_block method for showing it inside dashboard interface
  * @return string  img html
  */
 public function get_students_attendance_graph()
 {
     $students = $this->students;
     $attendance = new Attendance();
     // get data
     $attendances_faults_avg = array();
     if (is_array($students) && count($students) > 0) {
         foreach ($students as $student) {
             $student_id = $student['user_id'];
             //$student_info = api_get_user_info($student_id);
             // get average of faults in attendances by student
             $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
             if (!empty($results_faults_avg)) {
                 $attendances_faults_avg[$student['lastname']] = $results_faults_avg['porcent'];
             } else {
                 $attendances_faults_avg[$student['lastname']] = 0;
             }
         }
     }
     arsort($attendances_faults_avg);
     $usernames = array_keys($attendances_faults_avg);
     $faults = array();
     foreach ($usernames as $username) {
         $faults[] = $attendances_faults_avg[$username];
     }
     $graph = '';
     $img_file = '';
     if (is_array($usernames) && count($usernames) > 0) {
         // Defining data
         $data_set = new pData();
         $data_set->AddPoint($faults, "Promedio");
         $data_set->AddPoint($usernames, "Usuario");
         $data_set->AddAllSeries();
         $data_set->SetAbsciseLabelSerie("Usuario");
         // prepare cache for saving image
         $graph_id = $this->user_id . 'StudentEvaluationGraph';
         // the graph id
         $cache = new pCache(api_get_path(SYS_ARCHIVE_PATH));
         $data = $data_set->GetData();
         // return $this->DataDescription
         if ($cache->IsInCache($graph_id, $data_set->GetData())) {
             //if (0) {
             //if we already created the img
             $img_file = $cache->GetHash($graph_id, $data_set->GetData());
             // image file with hash
         } else {
             if (count($usernames) < 5) {
                 $height = 200;
             } else {
                 $height = count($usernames) * 40;
             }
             // Initialise the graph
             $test = new MyHorBar(400, $height + 30);
             $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8);
             $test->setGraphArea(100, 30, 370, $height);
             $test->drawFilledRoundedRectangle(7, 7, 393, $height, 5, 240, 240, 240);
             $test->drawRoundedRectangle(5, 5, 395, $height, 5, 230, 230, 230);
             $test->drawGraphArea(255, 255, 255, TRUE);
             //X axis
             $test->setFixedScale(0, 100, 10);
             //var_dump($data_set->GetDataDescription());
             $test->drawHorScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, 0, 0, TRUE);
             $test->setColorPalette(0, 255, 0, 0);
             $test->drawHorGrid(10, 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->drawHorBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE, 50);
             $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)) {
             $graph = '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '">';
         }
     } else {
         $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>';
     }
     return $graph;
 }
コード例 #2
0
ファイル: Graphs.php プロジェクト: srigi/nette-patients
 /**
  * Create graph (a .png file)
  *
  * @param string $file
  */
 public function generateGraph($file)
 {
     $patientValues = Storage::getInstance()->getPatientsData($file);
     /*
      * pGraph work
      */
     $dataSet = new pData();
     if (!empty($patientValues)) {
         $dataSet->AddPoint(array_keys($patientValues[$file]), 'label');
         $dataSet->SetAbsciseLabelSerie('label');
         $serie1 = array_values($patientValues[$file]);
         $average = round(array_sum($serie1) / count($serie1), 2);
         $dataSet->AddPoint($serie1, "Serie1");
         $dataSet->AddSerie("Serie1");
         // Initialise the graph
         $graph = new MyHorBar(450, 600);
         $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 8);
         $graph->setGraphArea(120, 60, 410, 550);
         $graph->drawFilledRoundedRectangle(7, 7, 443, 593, 5, 240, 240, 240);
         $graph->drawRoundedRectangle(5, 5, 443, 595, 5, 230, 230, 230);
         $graph->drawGraphArea(255, 255, 255, true);
         $graph->drawHorScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, true, 0, 2, true);
         $graph->drawHorGrid(10, true, 230, 230, 230, 50);
         // Draw the 0 line
         $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 6);
         $graph->drawTreshold($average, 143, 55, 72, true, false, 2, null, 90);
         // Draw the bar graph
         $graph->drawHorBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), false);
         // Finish the graph
         $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 10);
         $graph->drawLegend(15, 15, $dataSet->GetDataDescription(), 255, 255, 255);
         $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 10);
         $graph->drawTitle(170, 27, $file, 50, 50, 50, -1);
     } else {
         $graph = new pChart(450, 150);
         $graph->setGraphArea(120, 60, 410, 100);
         $graph->drawFilledRoundedRectangle(7, 7, 443, 143, 5, 240, 240, 240);
         $graph->drawRoundedRectangle(5, 5, 443, 145, 5, 230, 230, 230);
         $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 10);
         $graph->drawTitle(170, 27, $file, 50, 50, 50, -1);
         $graph->setFontProperties($this->fontsPath . '/tahoma.ttf', 36);
         $graph->drawTitle(125, 90, 'No data!', 245, 50, 50, -1);
     }
     $graph->Render(WWW_DIR . '/images/graphs/' . $file . '.png');
 }