/**
 * Генерация графика
 * @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();
}
Exemplo n.º 2
1
function generateGraph($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to)
{
    $myarr = graphTests($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to);
    $myarr1 = graphErrs($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to);
    $myarr2 = graphLbls($year, $month, $quarter, $biAnn, $dev, $patna, $duration, $from, $to);
    // Standard inclusions
    include "pChart/pChart/pData.class";
    include "pChart/pChart/pChart.class";
    // Dataset definition
    $DataSet = new pData();
    $DataSet->AddPoint($myarr, "Serie1");
    $DataSet->AddPoint($myarr1, "Serie2");
    $DataSet->AddPoint($myarr2, "Serie3");
    $DataSet->AddSerie("Serie1");
    $DataSet->AddSerie("Serie2");
    $DataSet->SetAbsciseLabelSerie("Serie3");
    $DataSet->SetSerieName("Test Resulting trends", "Serie1");
    $DataSet->SetSerieName("Errors in tests", "Serie2");
    $DataSet->SetYAxisName("Tests");
    // $DataSet->SetYAxisFormat("time");
    $DataSet->SetXAxisName("months");
    // Initialise the graph
    $Test = new pChart(750, 330);
    $Test->setFontProperties("Fonts/tahoma.ttf", 8);
    $Test->setGraphArea(85, 30, 650, 200);
    $Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
    $Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
    $Test->drawGraphArea(255, 255, 255, TRUE);
    $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2);
    $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
    // Draw the 0 line
    $Test->setFontProperties("Fonts/tahoma.ttf", 6);
    $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
    // Draw the line graph
    $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
    $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
    // Finish the graph
    $Test->setFontProperties("Fonts/tahoma.ttf", 8);
    $Test->drawLegend(90, 35, $DataSet->GetDataDescription(), 255, 255, 255);
    $Test->setFontProperties("Fonts/tahoma.ttf", 10);
    $Test->drawTitle(60, 22, "Test Summary", 50, 50, 50, 585);
    $Test->Render("mpdf.png");
}
Exemplo n.º 3
0
 function index()
 {
     $this->load->model('charge_model');
     $revenue = $this->charge_model->GetRevenueByDay($this->user->Get('client_id'));
     $data = array();
     if ($this->config->item('show_dashboard_chart') !== 'no' and !empty($revenue) and count($revenue) > 1) {
         $series = array();
         foreach ($revenue as $day) {
             $series[] = $day['revenue'];
             $series2[] = date("M j", strtotime($day['day']));
         }
         include APPPATH . 'libraries/pchart/pData.class';
         include APPPATH . 'libraries/pchart/pChart.class';
         // Dataset definition
         $DataSet = new pData();
         $DataSet->AddPoint($series, "Revenue");
         $DataSet->AddPoint($series2, "Serie2");
         $DataSet->AddAllSeries();
         $DataSet->SetAbsciseLabelSerie("Serie2");
         $DataSet->RemoveSerie("Serie2");
         $DataSet->SetXAxisName('Date');
         $DataSet->SetYAxisName('Revenue');
         //$DataSet->SetXAxisFormat('date');
         // Initialise the graph
         $Test = new pChart(1000, 260);
         $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 10);
         $Test->setGraphArea(90, 30, 960, 200);
         $Test->drawGraphArea(252, 252, 252);
         $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2);
         $Test->drawGrid(4, TRUE, 230, 230, 230, 255);
         // 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(APPPATH . 'libraries/pchart/Arial.ttf', 8);
         $Test->drawLegend(45, 35, $DataSet->GetDataDescription(), 255, 255, 255);
         $Test->setFontProperties(APPPATH . 'libraries/pchart/Arial.ttf', 10);
         //$Test->drawTitle(60,22,"Last 30 Days",50,50,50,585);
         $Test->Render(BASEPATH . '../writeable/rev_chart_' . $this->user->Get('client_id') . '.png');
     } else {
         $data['no_chart'] = 'true';
     }
     // get log
     $this->load->model('log_model');
     $log = $this->log_model->GetClientLog($this->user->Get('client_id'));
     $data['log'] = $log;
     $this->load->view(branded_view('cp/dashboard'), $data);
 }
  $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);   
  //$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);   
  $Test->setFontProperties("../lib/Fonts/tahoma.ttf",10);   
  $Test->drawTitle(60,22,"Evolution du classement ".$type." de ".$pseudo,50,50,50,585);   
  $Test->Stroke();      

?>
Exemplo n.º 5
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();
 }
Exemplo n.º 6
0
/**
 * This function draw the graphic to be displayed on the user view as an image
 *
 * @param array $sql_result
 * @param string $start_date
 * @param string $end_date
 * @param string $type
 * @author Jorge Frisancho Jibaja
 * @version OCT-22- 2010
 * @return string
 */
function grapher($sql_result, $start_date, $end_date, $type = "") {
    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';

    if (empty($start_date)) { $start_date =""; }
    if (empty($end_date)) { $end_date =""; }
    if ($type == ""){ $type = 'day'; }
    $main_year  = $main_month_year = $main_day = array();
    // get last 8 days/months
    $last_days      = 5;
    $last_months    = 3;
    for ($i = $last_days; $i >= 0; $i--) {
        $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
    }
    for ($i = $last_months; $i >= 0; $i--) {
        $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
    }

    $i = 0;
    if (is_array($sql_result) && count($sql_result) > 0) {
        foreach ($sql_result as $key => $data) {
            //creating the main array
            $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
            $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
            if ($i > 500) {
                break;
            }
            $i++;
        }

        switch ($type) {
            case 'day':
                $main_date = $main_day;
                break;
            case 'month':
                $main_date = $main_month_year;
                break;
            case 'year':
                $main_date = $main_year;
                break;
        }

        // the nice graphics :D
        $labels = array_keys($main_date);
        if (count($main_date) == 1) {
            $labels = $labels[0];
            $main_date = $main_date[$labels];
        }

        $data_set = new pData();
        $data_set->AddPoint($main_date, 'Q');
        if (count($main_date)!= 1) {
            $data_set->AddPoint($labels, 'Date');
        }
        $data_set->AddAllSeries();
        $data_set->RemoveSerie('Date');
        $data_set->SetAbsciseLabelSerie('Date');
        $data_set->SetYAxisName(get_lang('Minutes', ''));
        $graph_id = api_get_user_id().'AccessDetails'.api_get_course_id().$start_date.$end_date.$type;
        $data_set->AddAllSeries();

        $cache = new pCache();
        // the graph id
        $data = $data_set->GetData();

        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 {
            // if the image does not exist in the archive/ folder
            // Initialise the graph
            $test = new pChart(760, 230);

            //which schema of color will be used
            $quant_resources = count($data[0]) - 1;
            // Adding the color schemma
            $test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');

            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/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($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
            $test->drawGrid(4, TRUE, 230, 230, 230, 50);
            $test->setLineStyle(2);
            // Draw the 0 line
            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6);
            $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);

            if (count($main_date) == 1) {
                //Draw a graph
                echo '<strong>'.$labels.'</strong><br/>';
                $test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE);
            } else {
                //Draw the line graph
                $test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription());
                $test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255);
            }

            // Finish the graph
            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
            $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
            $test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585);

            //------------------
            //echo 'not in cache';
            $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
            ob_start();
            $test->Stroke();
            ob_end_clean();
            $img_file = $cache->GetHash($graph_id, $data_set->GetData());
        }
        $foo_img = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
        return $foo_img;
    } else {
        $foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8');
        return $foo_img;
    }

}
 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");
 }
Exemplo n.º 8
0
$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);
$Test->drawTitle(0, 0, "Average temperatures", 255, 255, 255, 700, 30, TRUE);
$Test->clearShadow();
// Draw the legend
$Test->setFontProperties("../Fonts/tahoma.ttf", 8);
$Test->drawLegend(610, 5, $DataSet->GetDataDescription(), 0, 0, 0, 0, 0, 0, 255, 255, 255, FALSE);
// Render the picture
$Test->Render("example25.png");
Exemplo n.º 9
0
 protected function generateGraphImage($finalData, $hourflag, $title = 'Sticky Charts', $x_axis_format = 'date')
 {
     $path = $this->config->item('csv_upload_path');
     if (!empty($finalData['data'])) {
         $DataSet = new pData();
         $in = 0;
         foreach ($finalData['data'] as $seriesData) {
             $in++;
             $seriesIndex = 'Serie' . $in;
             $DataSet->AddPoint($seriesData['data'], $seriesIndex);
             $DataSet->SetSerieName($seriesData['name'], $seriesIndex);
             $DataSet->AddSerie($seriesIndex);
         }
         $xAxisArray = array();
         $in++;
         $seriesIndex = 'Serie' . $in;
         $catCount = count($finalData['cat']);
         if ($catCount <= 10) {
             $DataSet->SetXAxisFormat($x_axis_format);
         }
         foreach ($finalData['cat'] as $catD) {
             if ($catCount > 10) {
                 $xAxisArray[] = '';
             } else {
                 $xAxisArray[] = strtotime($catD);
             }
         }
         $DataSet->SetYAxisFormat("number");
         $DataSet->AddPoint($xAxisArray, $seriesIndex);
         $DataSet->SetAbsciseLabelSerie($seriesIndex);
         $DataSet->SetYAxisName($finalData['y_title']);
         $DataSet->SetXAxisName($finalData['x_title']);
         // Initialise the graph
         $Test = new pChart(985, 458);
         $Test->drawBackground(247, 226, 180);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
         $Test->setGraphArea(40, 30, 950, 400);
         $Test->drawGraphArea(109, 110, 114, false);
         $Test->drawGrid(4, false, 0, 0, 0, 50);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 6);
         // Draw the line graph
         if ($title == 'Violation Report') {
             //!$hourflag &&
             $sCount = count($finalData['data']);
             if ($sCount > 0) {
                 for ($m = 0; $m < $sCount; $m++) {
                     $color = Color_handler::get_next($m);
                     $rgb = $color->get_rgb();
                     $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']);
                 }
             }
             $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 0, 0, 0, TRUE, 0, 0, TRUE);
             $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription());
         } else {
             $sCount = count($finalData['data']);
             if ($sCount > 0) {
                 for ($m = 0; $m < $sCount; $m++) {
                     $color = Color_handler::get_next($m % 3);
                     $rgb = $color->get_rgb();
                     $Test->setColorPalette($m, $rgb['r'], $rgb['g'], $rgb['b']);
                 }
             }
             $Test->setLineStyle(2);
             $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 0, 0, 0, TRUE, 0, 2);
             $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
             $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 2);
         }
         // Finish the graph
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 8);
         $Test->setFontProperties(APPPATH . '3rdparty/pchart/Fonts/tahoma.ttf', 10);
         $imgName = uniqid('graph_') . '.png';
         $Test->Render($path . $imgName);
         return upload_to_amazon_graphImage($imgName, $path);
     }
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 /**
  * Рисуем графики с помощью библиотеки pChart
  * @param object $model
  * @param integer $max_id
  * @param integer $x
  * @param integer $y
  * @param integer $y2
  */
 public function pChart($model, $max_id, $x, $y, $y2 = NULL)
 {
     /* Include the pData class */
     require_once Yii::getAlias('@app') . '/pChart/pChart/pData.class';
     require_once Yii::getAlias('@app') . '/pChart/pChart/pCache.class';
     require_once Yii::getAlias('@app') . '/pChart/pChart/pChart.class';
     //создаем объект данных
     $myData = new \pData();
     if (!$y2) {
         $datas = $model::find()->select([$x, $y])->andWhere("id > {$max_id} - 7")->all();
     } else {
         $datas = $model::find()->select([$x, $y, $y2])->andWhere("id > {$max_id} - 7")->all();
     }
     foreach ($datas as $key => $data) {
         $myData->AddPoint($data->{$x}, $x);
         $myData->AddPoint($data->{$y}, $y);
         if ($y2 != NULL) {
             $myData->AddPoint($data->{$y2}, $y2);
         }
     }
     //устанавливаем точки с датами
     //на ось абсцисс
     $myData->SetAbsciseLabelSerie($x);
     //помечаем данные как предназначеные для
     //отображения
     $myData->AddSerie($y);
     $myData->AddSerie($y2);
     //устанавливаем имена
     $myData->SetSerieName($y);
     $myData->SetSerieName($y2);
     //создаем график шириной  и высотой  px
     $graph = new \pChart(340, 130);
     //устанавливаем шрифт и размер шрифта
     $graph->setFontProperties(Yii::getAlias('@app') . '/pChart/Fonts/tahoma.ttf', true, 8);
     //координаты левой верхней вершины и правой нижней
     //вершины графика
     $graph->setGraphArea(35, 20, 330, 110);
     //добавляем бэкграунд
     $graph->drawBackground(255, 0, 0);
     $graph->drawGraphAreaGradient(132, 153, 172, 50, TARGET_BACKGROUND);
     //рисуем заполненный четырехугольник
     $graph->drawFilledRoundedRectangle(7, 7, 993, 493, 5, 240, 240, 240);
     //теперь незаполненный для эффекта тени
     $graph->drawRoundedRectangle(5, 5, 995, 495, 5, 0, 200, 0);
     //прорисовываем фон графика
     $graph->drawGraphArea(200, 255, 255, TRUE);
     //устанавливаем данные для графиков
     $graph->drawScale($myData->GetData(), $myData->GetDataDescription(), SCALE_NORMAL, 10, 10, 10, true, 0, 2);
     //рисуем сетку для графика
     $graph->drawGrid(4, TRUE, 200, 230, 230, 50);
     //прорисовываем линейные графики
     $graph->drawLineGraph($myData->GetData(), $myData->GetDataDescription());
     // рисуем точки на графике
     $graph->drawPlotGraph($myData->GetData(), $myData->GetDataDescription(), 3, 2, 255, 255, 255);
     // пишем в подвале некоторый текст
     $graph->setFontProperties(Url::to('@app/pChart/Fonts/tahoma.ttf', true), 8);
     $graph->drawTextBox(805, 470, 990, 480, "{$x}", 0, 150, 150, 150, ALIGN_CENTER, TRUE, -1, -1, -1, 30);
     $graph->drawTextBox(10, 470, 140, 480, "{$y}", 0, 250, 250, 250, ALIGN_CENTER, TRUE, -1, -1, -1, 30);
     //ложим легенду
     $graph->drawLegend(90, 35, $myData->GetDataDescription(), 255, 255, 255);
     //Пишем заголовок
     $graph->setFontProperties(Url::to('@app/pChart/Fonts/tahoma.ttf', true), 8);
     $graph->drawTitle(480, 22, "График", 50, 50, 50, -1, -1, true);
     //выводим в браузер
     $graph->Render(Url::to('@app/web/uploads/' . $y . '.png'));
 }
Exemplo n.º 12
0
 /**
  * Draw line style chart
  * @return unknown
  */
 protected function drawLine()
 {
     // prepare font & series
     $this->_prepareSerie();
     $this->_prepareFont();
     // init chart params
     $outer_w = $this->w - 5;
     // Outer frame witdh
     $outer_h = $this->h - 5;
     // Outer frame heigth
     $inner_w = $this->w - 7;
     // Inner frame witdh
     $inner_h = $this->h - 7;
     // Inner frame heigth
     $chart_w = $this->w - 150;
     // Chart frame witdh
     $chart_h = $this->h - 40;
     // Chart frame heigth
     $title_w = $this->w - 200;
     // Title width
     $title_h = 45;
     // Title height
     $legend_w = $chart_w + 30;
     // Legend width
     $legend_h = 40;
     // Legend height
     // chart styles
     $grid = isset($this->p['grid']) ? $this->p['grid'] : false;
     $plot = isset($this->p['plot']) ? $this->p['plot'] : false;
     $curve = isset($this->p['curve']) ? $this->p['curve'] : false;
     $filled = isset($this->p['filled']) ? $this->p['filled'] : false;
     // fill chart
     $this->chart->drawBackground(255, 255, 255);
     $this->chart->setFontProperties($this->font, 7);
     // set font and size
     $this->chart->drawRoundedRectangle(5, 5, $outer_w, $outer_h, 10, 230, 230, 230);
     // drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
     $this->chart->drawFilledRoundedRectangle(7, 7, $inner_w, $inner_h, 10, 240, 240, 240);
     // drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
     $this->chart->setGraphArea(70, 40, $chart_w, $chart_h);
     // setGraphArea($X1,$Y1,$X2,$Y2)
     $this->chart->drawGraphArea(255, 255, 255, TRUE);
     // drawGraphArea($R,$G,$B)
     $this->chart->drawScale($this->data->GetData(), $this->data->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, $this->margin, $this->skip);
     // drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
     $this->data->RemoveSerie('DEFAULT_SCALE');
     // clear scale serie for setScale method
     // draw grid
     if ($grid) {
         $this->chart->drawGrid(3, TRUE, 230, 230, 230, 50);
         // drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=255)
     }
     // draw the 0 line
     //$this->chart->setFontProperties($this->font,6);
     //$this->chart->drawTreshold(0,143,55,72,TRUE,TRUE);
     // draw the cubic curve graph
     if ($curve) {
         $this->chart->drawCubicCurve($this->data->GetData(), $this->data->GetDataDescription());
         if ($filled) {
             $this->chart->drawFilledCubicCurve($this->data->GetData(), $this->data->GetDataDescription(), 0.1, 50);
             // filled cubic curve graph
         }
         // draw the line graph
     } else {
         $this->chart->drawLineGraph($this->data->GetData(), $this->data->GetDataDescription());
         if ($filled) {
             $this->chart->drawFilledLineGraph($this->data->GetData(), $this->data->GetDataDescription(), 50);
         }
     }
     // plot style point
     if ($plot) {
         $this->chart->drawPlotGraph($this->data->GetData(), $this->data->GetDataDescription(), 3, 2, 255, 255, 255, true);
         // drawPlotGraph(&$Data,&$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1,$Shadow=FALSE)
     }
     // add Title
     $this->chart->setFontProperties($this->font, 10);
     $this->chart->drawTitle(40, 0, $this->title, 50, 50, 50, $title_w, $title_h);
     // drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
     // add Legend
     $this->chart->setFontProperties($this->font, 8);
     $this->chart->drawLegend($legend_w, $legend_h, $this->data->GetDataDescription(), 255, 255, 255);
     // drawLegend($description,$R,$G,$B)
 }
Exemplo n.º 13
0
//  Dataset definition
$DataSet = new pData();
$DataSet->AddPoint(array($data1, $data2, $data3, $data4, $data5), "Serie1");
$DataSet->AddPoint(array("January", "February", "March", "April", "May", "June"), "Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test = new pChart(700, 230);
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->setGraphArea(60, 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(), 5, 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 area
$Test->drawArea($DataSet->GetData(), "Serie1", "Serie3", 239, 238, 227, 50);
// Draw the line graph
$DataSet->RemoveSerie("Serie1");
$DataSet->RemoveSerie("Serie3");
$Test->drawLineGraph($DataSet->AddPoint(array($data1, $data2, $data3, $data4, $data5), "Serie1"), $DataSet->GetDataDescription(), 0.1);
$Test->drawPlotGraph($DataSet->AddPoint(array($data1, $data2, $data3, $data4, $data5), "Serie1"), $DataSet->GetDataDescription(), 0, 2, 3, 24, 30);
// Finish the graph
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->drawLegend(65, 35, $DataSet->GetDataDescription(), 250, 250, 250);
$Test->setFontProperties("Fonts/tahoma.ttf", 10);
$Test->drawTitle(60, 22, "Reporting Rate", 50, 50, 50, 585);
$Test->Render("example45.png");
Exemplo n.º 14
0
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetYAxisName("Usage");
$DataSet->SetXAxisName("Hour");
$DataSet->SetYAxisUnit("%");
#$DataSet->SetXAxisFormat("date");
// Initialise the graph
$Test = new pChart(900, 225);
$Test->setColorPalette(0, 126, 185, 245);
$Test->setFontProperties("{$font}", 8);
$Test->setGraphArea(75, 35, 890, 190);
#$Test->drawFilledRoundedRectangle(7,7,450,223,5,240,240,240);
#$Test->drawRoundedRectangle(5,5,450,225,5,230,230,230);
$Test->drawGraphArea(255, 255, 255, FALSE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 75, 75, 75, TRUE, 0, 2);
$Test->drawGrid(1, TRUE, 240, 240, 240);
#$Test->drawGrid(4,TRUE);
// Draw the 0 line
$Test->setFontProperties("{$font}", 6);
$Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 0);
// Finish the graph
$Test->setFontProperties("{$font}", 8);
#$Test->drawLegend(90,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("{$font}", 11);
$Test->drawTitle(325, 25, "CPU", 75, 75, 75, 585);
$Test->Stroke();
?>
 
 /**
  * @author Patrick plichart
  * @param string localgraphid an identifier for the graph to be displayed
  * @param array $datax	a flat sery of x labels
  * @param array $setOfySeries	an array of y series to be drawn (needs to be consistent with xsery), keys indicates the legend title
  * @param string $title the title of the graph
  * @param string xAxisLabel label of the x Axis
  * @param string yAxisLabel label of the y Axis
  * @return string the url of the generated graph
  */
 private function getChart($localGraphId, $datax, $setOfySeries, $title, $type = "bar", $xAxisLabel = "", $yAxisLabel = "", $r = "208", $g = "2", $b = "57")
 {
     // Dataset definition
     if (count($datax) == 0) {
         throw new \common_exception_NoContent("Empty data set");
     }
     $dataSet = new \pData();
     foreach ($setOfySeries as $legend => $ysery) {
         $dataSet->AddPoint($ysery, $legend);
         $dataSet->SetSerieName($legend, $legend);
     }
     $dataSet->AddAllSeries();
     $dataSet->AddPoint($datax, "xLabels");
     $dataSet->SetYAxisName($yAxisLabel);
     $dataSet->SetXAxisName($xAxisLabel);
     $dataSet->SetAbsciseLabelSerie("xLabels");
     // Initialise the graph
     $graph = new \pChart(490, 260);
     $graph->createColorGradientPalette($r, $g, $b, $r, $g, $b, 5);
     // aa is way too slow here
     $graph->Antialias = false;
     $graph->setFontProperties(fontName, 8);
     $graph->setGraphArea(55, 40, 450, 200);
     // draw the background rectangle
     $graph->drawFilledRoundedRectangle(7, 7, 655, 253, 5, 240, 240, 240);
     $graph->drawRoundedRectangle(5, 5, 655, 225, 5, 230, 230, 230);
     $graph->drawGraphArea(255, 255, 255, true);
     $graph->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, true, 0, 2, true);
     $graph->drawGrid(4, true, 230, 230, 230, 50);
     // Draw the 0 line
     $graph->setFontProperties(fontName, 6);
     $graph->drawTreshold(0, 143, 55, 72, true, true);
     // Draw the bar graph
     switch ($type) {
         case "bar":
             $graph->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), true);
             break;
         case "line":
             $graph->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription());
             $graph->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255);
             break;
     }
     // Finish the graph
     $graph->setFontProperties(fontName, 9);
     $graph->drawLegend(50, 220, $dataSet->GetDataDescription(), 254, 254, 254);
     $graph->setFontProperties(fontName, 8);
     $graph->drawTitle(15, 30, $title, 50, 80, 50);
     $url = $this->getUniqueMediaFileName($localGraphId, "png");
     $graph->Render(ROOT_PATH . $url);
     return ROOT_URL . $url;
 }
 protected function _createVisitsGraph()
 {
     // load pChart graphic library
     $this->_loadLibs();
     // définition des données à afficher
     $dataSet = new pData();
     // need config, to know which data user wants to display : visits, unique visitors, pageviews
     $sefConfig = Sh404sefFactory::getConfig();
     $dataTypeString = str_replace('ga:', '', $sefConfig->analyticsDashboardDataType);
     // get data from response
     $data = array();
     $maxY = 0;
     foreach ($this->_rawData['visits'] as $entry) {
         $data[] = $entry->{$dataTypeString};
         if ($entry->{$dataTypeString} > $maxY) {
             $maxY = $entry->{$dataTypeString};
         }
     }
     // format dates
     $dates = Sh404sefHelperAnalytics::formatAbciseDates($this->_rawData['visits'], $this->_options);
     $dataSet->AddPoint($data, $dataTypeString);
     $dataSet->AddPoint($dates, "dates");
     $dataSet->addSerie($dataTypeString);
     $dataSet->SetAbsciseLabelSerie("dates");
     $label = JText::_('COM_SH404SEF_ANALYTICS_DATA_' . strtoupper($dataTypeString));
     $dataSet->SetSerieName($label, $dataTypeString);
     // Initialise the graph
     $w = $this->_options['cpWidth'];
     $w = empty($w) ? 400 : intval($w - 40);
     $h = 225;
     $centreX = intval(0.5 * $w);
     $centreY = intval(0.5 * $h);
     $chart = new pChart($w, $h);
     $fontSize = 8;
     // calculate left margin based on max value to display
     $leftMargin = 20 + $fontSize + 20 + $fontSize * strlen($maxY);
     $bottomMargin = 5 + $fontSize * 6;
     switch ($this->_options['groupBy']) {
         case 'ga:year,ga:month,ga:week,ga:day':
             $YAxisName = JText::_('Day');
             break;
             // date string represents a week number
         // date string represents a week number
         case 'ga:year,ga:month,ga:week':
             $YAxisName = JText::_('Week');
             break;
         case 'ga:year,ga:month':
             $YAxisName = JText::_('Month');
             break;
     }
     $dataSet->SetYAxisName($label . JText::_('COM_SH404SEF_ANALYTICS_REPORT_PER_LABEL') . $YAxisName);
     $chart->setFontProperties($this->_baseChartPath . DS . 'Fonts/arial.ttf', $fontSize);
     $chart->setGraphArea($leftMargin, 30, $w - 20, $h - $bottomMargin);
     $chart->drawFilledRoundedRectangle(7, 7, $w - 7, $h - 7, 5, 240, 240, 240);
     $chart->drawRoundedRectangle(5, 5, $w - 5, $h - 5, 5, 230, 230, 230);
     $chart->drawGraphArea(255, 255, 255, TRUE);
     $d = $dataSet->GetData();
     if (!empty($d)) {
         $chart->drawScale($d, $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 60, 0, false);
         $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
         // Draw the 0 line
         $chart->setFontProperties($this->_baseChartPath . DS . 'Fonts/arial.ttf', $fontSize);
         $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
         // Draw the line graph
         $chart->drawLineGraph($d, $dataSet->GetDataDescription());
         $chart->drawPlotGraph($d, $dataSet->GetDataDescription(), 3, 2, 255, 255, 255);
     }
     // create a temporary file for
     $user =& JFactory::getUser();
     // make sure the root tmp dir exists
     $rootDir = 'tmp' . DS . 'sh404sef_analytics';
     Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $rootDir);
     // file name is per user
     $basePath = $rootDir . DS . md5('useless_' . $user->id . '_hashing') . DS;
     // create path and make sure there's an index.html file in it
     Sh404sefHelperFiles::createDirAndIndex(JPATH_ROOT . DS . $basePath);
     $imageFileName = Sh404sefHelperAnalytics::createTempFile($basePath, $this->_options['report'] . '.' . $this->_options['accountId'] . '.visits.' . $dataTypeString);
     $chart->Render(JPATH_ROOT . DS . $imageFileName);
     // need cleaning up, so let's remove all report files for that user older than an hour or so
     Sh404sefHelperAnalytics::cleanReportsImageFiles(JPATH_ROOT . DS . $basePath, $age = 4000);
     return JURI::root() . $imageFileName;
 }
Exemplo n.º 17
0
 function showGraph($searchInfo = '')
 {
     $conditions = empty($searchInfo['keywordId']) ? "" : " and s.keyword_id=" . $searchInfo['keywordId'];
     $conditions .= empty($searchInfo['seId']) ? "" : " and s.searchengine_id=" . $searchInfo['seId'];
     $sql = "select s.*,se.domain \r\n\t\t\t\t\tfrom searchresults s,searchengines se  \r\n\t\t\t\t\twhere s.searchengine_id=se.id \r\n\t\t\t\t\tand time>= {$searchInfo['fromTime']} and time<{$searchInfo['toTime']} {$conditions}  \r\n\t\t\t\t\torder by s.time";
     $repList = $this->db->select($sql);
     $reportList = array();
     $seList = array();
     foreach ($repList as $repInfo) {
         $var = $repInfo['searchengine_id'] . $repInfo['keyword_id'] . $repInfo['time'];
         if (empty($reportList[$var])) {
             $reportList[$var] = $repInfo;
         } else {
             if ($repInfo['rank'] < $reportList[$var]['rank']) {
                 $reportList[$var] = $repInfo;
             }
         }
         if (empty($seList[$repInfo['searchengine_id']])) {
             $seList[$repInfo['searchengine_id']] = $repInfo['domain'];
         }
     }
     asort($seList);
     $dataList = array();
     foreach ($reportList as $repInfo) {
         $seId = $repInfo['searchengine_id'];
         $dataList[$repInfo['time']][$seId] = $repInfo['rank'];
     }
     # Dataset definition
     $dataSet = new pData();
     foreach ($dataList as $dataInfo) {
         $i = 1;
         foreach ($seList as $seId => $seVal) {
             $val = empty($dataInfo[$seId]) ? 0 : $dataInfo[$seId];
             $dataSet->AddPoint($val, "Serie" . $i++);
         }
     }
     $i = 1;
     foreach ($seList as $seDomain) {
         $dataSet->AddSerie("Serie{$i}");
         $dataSet->SetSerieName($seDomain, "Serie{$i}");
         $i++;
     }
     $serieCount = count($seList) + 1;
     $dataSet->AddPoint(array_keys($dataList), "Serie{$serieCount}");
     $dataSet->SetAbsciseLabelSerie("Serie{$serieCount}");
     $dataSet->SetXAxisName("Date");
     $dataSet->SetYAxisName("Rank");
     $dataSet->SetXAxisFormat("date");
     # Initialise the graph
     $chart = new pChart(720, 520);
     $chart->setFontProperties("fonts/tahoma.ttf", 8);
     $chart->setGraphArea(85, 30, 670, 425);
     $chart->drawFilledRoundedRectangle(7, 7, 713, 513, 5, 240, 240, 240);
     $chart->drawRoundedRectangle(5, 5, 715, 515, 5, 230, 230, 230);
     $chart->drawGraphArea(255, 255, 255, TRUE);
     $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 90, 2);
     $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
     # Draw the 0 line
     $chart->setFontProperties("fonts/tahoma.ttf", 6);
     $chart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
     # Draw the line graph
     $chart->drawLineGraph($dataSet->GetData(), $dataSet->GetDataDescription());
     $chart->drawPlotGraph($dataSet->GetData(), $dataSet->GetDataDescription(), 3, 2, 255, 255, 255);
     $j = 1;
     $chart->setFontProperties("fonts/tahoma.ttf", 10);
     foreach ($seList as $seDomain) {
         $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), "Serie" . $j++);
     }
     # Finish the graph
     $chart->setFontProperties("fonts/tahoma.ttf", 8);
     $chart->drawLegend(90, 35, $dataSet->GetDataDescription(), 255, 255, 255);
     $chart->setFontProperties("fonts/tahoma.ttf", 10);
     $chart->drawTitle(60, 22, "Keyword Position Report", 50, 50, 50, 585);
     $chart->stroke();
 }
Exemplo n.º 18
0
$DataSet = new pData();
$canvas = new GDCanvas(700, 230);
$Chart = new pChart(700, 230, $canvas);
// Dataset definition
CSVImporter::ImportFromCSV($DataSet, "../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0);
$DataSet->AddAllSeries();
$DataSet->setAbscissaLabelSeries();
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->setGraphArea(60, 30, 680, 200);
$canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
$canvas->drawRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow());
$Chart->drawGraphBackground(new BackgroundStyle(new Color(255), TRUE));
$Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);
$Chart->drawGrid(new GridStyle(4, TRUE, new Color(230, 230, 230), TRUE));
// Draw the 0 line
$Chart->setFontProperties("../Fonts/tahoma.ttf", 6);
$Chart->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
// Draw the area
$Chart->drawArea($DataSet, "Serie 1", "Serie 3", new Color(239, 238, 227));
// Draw the line graph
$Chart->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Chart->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, new Color(255));
// Finish the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->drawLegend(65, 35, $DataSet->GetDataDescription(), new Color(250));
$Chart->setFontProperties("../Fonts/tahoma.ttf", 10);
$Chart->drawTitle(60, 22, "Example 4", new Color(50), 585);
$Chart->Render("Example4.png");
header("Content-Type:image/png");
readfile("Example4.png");
Exemplo n.º 19
0
}
if ($p6 != '' && $c6r != 0) {
    $Test->setColorPalette(5, $c6r, $c6g, $c6b);
}
if ($p7 != '' && $c7r != 0) {
    $Test->setColorPalette(6, $c7r, $c7g, $c7b);
}
if ($p8 != '' && $c8r != 0) {
    $Test->setColorPalette(7, $c8r, $c8g, $c8b);
}
if ($p9 != '' && $c9r != 0) {
    $Test->setColorPalette(8, $c9r, $c9g, $c9b);
}
//---------------------------- Draw points
if ($_GET['points'] == '1') {
    $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $point);
    //plot
}
//---------------------------- Draw graphics
if ($_GET['gtype'] == 'curve') {
    $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
} elseif ($_GET['gtype'] == 'bar') {
    $Test->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), FALSE);
} elseif ($_GET['gtype'] == 'line') {
    $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
} elseif ($_GET['gtype'] == 'plot') {
    $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), $point);
} elseif ($_GET['gtype'] == 'fline') {
    $Test->drawFilledLineGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 20, FALSE);
} elseif ($_GET['gtype'] == 'fcurve') {
    $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 20, FALSE);
Exemplo n.º 20
0
 /**
  * Creates the object and prepares it for rendering.
  * Does all the calculation like borders, margins, paddings ....
  *
  * @return void
  */
 private function preGraphCreation()
 {
     // Initialize the graph
     $this->objChart = new pChart($this->intWidth, $this->intHeight);
     //set the color palette to be used
     foreach ($this->arrDefaultColorPalette as $intKey => $strCurrentColor) {
         $arrCurColor = hex2rgb($strCurrentColor);
         $this->objChart->setColorPalette($intKey, $arrCurColor[0], $arrCurColor[1], $arrCurColor[2]);
     }
     //calculate all needed params, draw that funky shit
     //the outer bounding and pane - rounded and with sharp corners
     $arrBackgroundColor = hex2rgb($this->strBackgroundColor);
     if ($this->bitRoundedCorners) {
         $this->objChart->drawFilledRoundedRectangle(2, 2, $this->intWidth - 3, $this->intHeight - 3, 5, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]);
         $arrOuterBack = hex2rgb($this->strOuterFrameColor);
         $this->objChart->drawRoundedRectangle(0, 0, $this->intWidth - 1, $this->intHeight - 1, 5, $arrOuterBack[0], $arrOuterBack[1], $arrOuterBack[2]);
     } else {
         $this->objChart->drawFilledRectangle(0, 0, $this->intWidth, $this->intHeight, $arrBackgroundColor[0], $arrBackgroundColor[1], $arrBackgroundColor[2]);
     }
     //the graph area - x and or y-axis label present?
     if ($this->bitRenderLegend) {
         $intRightMargin = 10;
     } else {
         $intRightMargin = 20;
     }
     $intTopMargin = 15;
     $intBottomMargin = 30;
     $intLeftMargin = 40;
     $intLegendWidth = 0;
     if ($this->bitRenderLegend) {
         $intLegendWidth = 120;
     }
     $intWidth = $this->intWidth - $intRightMargin - $intLegendWidth;
     $intHeight = $this->intHeight - $intBottomMargin;
     $intLeftStart = $intLeftMargin;
     $intTopStart = $intTopMargin;
     if ($this->strYAxisTitle != "") {
         $intLeftStart += 15;
         //$intWidth -= 15; //TODO: why not needed?
     }
     if ($this->strXAxisTitle != "") {
         $intHeight -= 15;
     }
     if ($this->strGraphTitle != "") {
         //$intHeight -= 12; //TODO: why not needed???
         $intTopStart += 12;
     }
     if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) {
         $this->objChart->setGraphArea($intLeftStart, $intTopStart, $intWidth, $intHeight);
         $arrPaneBackground = hex2rgb($this->strGraphBackgroundColor);
         $this->objChart->drawGraphArea($arrPaneBackground[0], $arrPaneBackground[1], $arrPaneBackground[2], true);
     }
     $arrFontColors = hex2rgb($this->strFontColor);
     $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 8);
     //set up the axis-titles
     if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR || $this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) {
         if ($this->strXAxisTitle != "") {
             $this->objDataset->SetXAxisName($this->strXAxisTitle);
         }
         if ($this->strYAxisTitle != "") {
             $this->objDataset->SetYAxisName($this->strYAxisTitle);
         }
     }
     //the x- and y axis, in- / exclusive margins
     if ($this->bitAdditionalDatasetAdded && $this->bitScaleFromAdditionalDataset) {
         $this->objChart->drawScale($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true);
     } else {
         if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) {
             $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_START0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true);
         } else {
             if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) {
                 $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_ADDALLSTART0, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, true);
             } else {
                 if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) {
                     $this->objChart->drawScale($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), SCALE_NORMAL, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], TRUE, $this->intXAxisAngle, 1, false);
                 }
             }
         }
     }
     //the background grid
     if ($this->intCurrentGraphMode != $this->GRAPH_TYPE_PIE) {
         $arrGridColor = hex2rgb($this->strGridColor);
         $this->objChart->drawGrid(4, true, $arrGridColor[0], $arrGridColor[1], $arrGridColor[2], 50);
     }
     if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_LINE) {
         // Draw the line graph
         $this->objChart->drawLineGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription());
         //dots in line
         $this->objChart->drawPlotGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 3, 2, 255, 255, 255);
     } else {
         if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_BAR) {
             //the zero-line
             $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6);
             $this->objChart->drawBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), TRUE);
             $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
             //if given, render the line-plots on top
             if ($this->bitAdditionalDatasetAdded) {
                 //the line itself
                 $this->objChart->drawLineGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription());
                 //the dots
                 $this->objChart->drawPlotGraph($this->objAdditionalDataset->GetData(), $this->objAdditionalDataset->GetDataDescription(), 3, 2, 255, 255, 255);
             }
         } else {
             if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_STACKEDBAR) {
                 //the zero-line
                 $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 6);
                 $this->objChart->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
                 $this->objChart->drawStackedBarGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 75);
             } else {
                 if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) {
                     $this->objChart->drawPieGraph($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), ceil($this->intWidth / 2) - 20, ceil($this->intHeight / 2), ceil($intHeight / 2) + 20, PIE_PERCENTAGE, TRUE, 50, 20, 5);
                 }
             }
         }
     }
     //render values?
     if (count($this->arrValueSeriesToRender) > 0) {
         $this->objChart->writeValues($this->objDataset->GetData(), $this->objDataset->GetDataDescription(), $this->arrValueSeriesToRender);
     }
     // Finish the graph
     $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 7);
     //set up the legend
     if ($this->bitRenderLegend) {
         if ($this->intCurrentGraphMode == $this->GRAPH_TYPE_PIE) {
             $this->objChart->drawPieLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $this->objDataset->GetData(), $this->objDataset->GetDataDescription(), 255, 255, 255);
         } else {
             $arrLegend = $this->objDataset->GetDataDescription();
             //merge legends
             if ($this->bitAdditionalDatasetAdded) {
                 $arrAdditionalLegend = $this->objAdditionalDataset->GetDataDescription();
                 foreach ($arrAdditionalLegend["Description"] as $strKey => $strName) {
                     $arrLegend["Description"][$strKey] = $strName;
                 }
             }
             $this->objChart->drawLegend($this->intWidth - $intLegendWidth - $intRightMargin + 10 - $this->intLegendAdditionalMargin, $intTopStart, $arrLegend, 255, 255, 255);
         }
     }
     //draw the title
     if ($this->strGraphTitle != "") {
         $this->objChart->setFontProperties(class_resourceloader::getInstance()->getCorePathForModule("module_system", true) . "/module_system/system" . $this->strFont, 10);
         $this->objChart->drawTitle(0, $intTopMargin, $this->strGraphTitle, $arrFontColors[0], $arrFontColors[1], $arrFontColors[2], $this->intWidth, 10);
     }
 }
Exemplo n.º 21
0
    $DataSet->AddPoint($date, 'SerieDate');
    $DataSet->AddSerie('SerieSkill');
    $DataSet->SetAbsciseLabelSerie('SerieDate');
    $DataSet->SetSerieName('Skill', 'SerieSkill');
    $DataSet->SetSerieName('Session', 'SerieSession');
    $Chart->setFontProperties(IMAGE_PATH . '/sig/font/DejaVuSans.ttf', 7);
    $DataSet->SetYAxisName('Skill');
    $DataSet->SetYAxisUnit('K');
    $Chart->setColorPalette(0, 255, 255, 0);
    $Chart->drawRightScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, $color['red'], $color['green'], $color['blue'], TRUE, 0, 0);
    $Chart->drawGrid(1, FALSE, 55, 55, 55, 100);
    $Chart->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
    $Chart->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
    $Chart->clearShadow();
    $Chart->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30);
    $Chart->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 1, 1, 255, 255, 255);
    $Chart->clearScale();
    $DataSet->RemoveSerie('SerieSkill');
    $DataSet->AddSerie('SerieSession');
    $DataSet->SetYAxisName('Session');
    $DataSet->SetYAxisUnit('');
    $Chart->setColorPalette(1, 255, 0, 0);
    $Chart->setColorPalette(2, 0, 0, 255);
    $Chart->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, $color['red'], $color['green'], $color['blue'], TRUE, 0, 0);
    $Chart->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
    $Chart->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
    $Chart->clearShadow();
    $Chart->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 1, 1, 255, 255, 255);
    $Chart->setFontProperties(IMAGE_PATH . '/sig/font/DejaVuSans.ttf', 7);
    $Chart->drawHorizontalLegend(235, -1, $DataSet->GetDataDescription(), 0, 0, 0, 0, 0, 0, $color['red'], $color['green'], $color['blue'], FALSE);
}
Exemplo n.º 22
0
 function generate_graph_image($outputfile)
 {
     // Create Graph Dataset and set axis attributes
     $graphData = new pData();
     $graphData->setYAxisName($this->ytitle);
     $graphData->AddPoint($this->xlabels, "xaxis");
     //$graphData->SetSerieName("xaxis","xaxis");
     $graphData->SetAbsciseLabelSerie("xaxis");
     $graphData->setXAxisName($this->xtitle);
     // Add each series of plot values to dataset, but Reportico will
     // duplicate series were the same data are displayed in different forms
     // so only add each unique series once
     $seriesadded = array();
     foreach ($this->plot as $k => $v) {
         $series = $v["name"] . $k;
         $graphData->AddPoint($v["data"], $series);
         $graphData->SetSerieName($v["legend"], $series);
         $graphData->AddSerie($series);
     }
     /*
     switch ( $this->xgriddisplay )
     {
     	case "all":
     		$graph->xgrid->Show(true,true);
     		break;
     	case "major":
     		$graph->xgrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->xgrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->xgrid->Show(false,false);
     		break;
     }
     
     switch ( $this->ygriddisplay )
     {
     	case "all":
     		$graph->ygrid->Show(true,true);
     		break;
     	case "major":
     		$graph->ygrid->Show(true,false);
     		break;
     	case "minor":
     		$graph->ygrid->Show(false,true);
     		break;
     	case "none":
     	default:
     		$graph->ygrid->Show(false,false);
     		break;
     }
     */
     /*
     $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize);
     $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor);
     $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize);
     $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor);
     $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize);
     $graph->xaxis->title->SetColor($xtitlecolor);
     $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize);
     $graph->yaxis->title->SetColor($ytitlecolor);
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->SetLabelMargin(15); 
     $graph->yaxis->SetLabelMargin(15); 
     $graph->xaxis->SetTickLabels($this->xlabels);
     $graph->xaxis->SetTextLabelInterval($xticklabint);
     $graph->yaxis->SetTextLabelInterval($yticklabint);
     $graph->xaxis->SetTextTickInterval($xtickinterval);
     $graph->yaxis->SetTextTickInterval($ytickinterval);
     */
     /*
     if ( $gridpos == "front" )
     	$graph->SetGridDepth(DEPTH_FRONT); 
     */
     // Display the graph
     /*?$graph->Stroke();*/
     $this->apply_defaults_internal();
     //echo $this->width_pdf_actual.",".$this->height_pdf_actual."<BR>";
     $graphImage = new pChart($this->width_pdf_actual, $this->height_pdf_actual);
     /* Turn of Antialiasing */
     $graphImage->Antialias = TRUE;
     // Add gradient fill from chosen background color to white
     $startgradient = htmltorgb("#ffffff");
     //$graphImage->drawGradientArea(0,0,$width,$height,DIRECTION_VERTICAL,array(
     //"StartR"=>$startgradient[0], "StartG"=>$startgradient[1], "StartB"=>$startgradient[2],
     //"EndR"=>$color[0], "EndG"=>$color[1], "EndB"=>$color[2],"Alpha"=>100));
     /* Add a border to the picture */
     //$graphImage->drawRectangle(0,0,$width - 1,$height - 1,200,200,200);
     $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xaxisfont, $this->xaxisfontsize);
     /* Define the chart area */
     $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright_actual, $this->height_pdf_actual - $this->marginbottom_actual);
     $graphImage->drawFilledRoundedRectangle(3, 3, $this->width_pdf_actual - 3, $this->height_pdf_actual - 3, 5, 240, 240, 240);
     $graphImage->drawRoundedRectangle(1, 1, $this->width_pdf_actual - 1, $this->height_pdf_actual - 1, 5, 230, 230, 230);
     // Before plotting a series ensure they are all not drawable.
     /// Plot the chart data
     $stackeddrawn = false;
     $linedrawn = false;
     $scatterdrawn = false;
     $piedrawn = false;
     $stackedexists = false;
     $overlayexists = false;
     $barexists = false;
     foreach ($this->plot as $k => $v) {
         if ($v["type"] == "OVERLAYBAR") {
             $overlayexists = true;
         }
         if ($v["type"] == "STACKEDBAR") {
             $stackedexists = true;
         }
         if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") {
             $barexists = true;
         }
         // Set plot colors
         if ($v["linecolor"]) {
             $graphImage->Palette[$k] = htmltorgb_pchart($v["linecolor"]);
         }
         $url .= "&plotlinecolor{$k}=" . $v["linecolor"];
     }
     $scale_drawing_mode = SCALE_NORMAL;
     $scale_drawing_mode = SCALE_START0;
     // For stacked charts fix up the Max and Min values;
     if ($stackedexists) {
         $scale_drawing_mode = SCALE_ADDALL;
         $scaleMin = "Unknown";
         $scaleMax = 0;
         $min = false;
         $max = false;
         foreach ($plot as $k => $v) {
             if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                 $series = $v["name"] . $k;
                 minmaxValueOfSeries($v["data"], $min, $max);
                 if ($scaleMin == "Unknown" || $min < $scaleMin) {
                     $scaleMin = $min;
                 }
                 $scaleMax = $scaleMax + $max;
             }
         }
         if ($scaleMin > 0) {
             $scaleMin = 0;
         }
         $range = $scaleMax - $scaleMin;
         // Make scales based on 5% of the range of values
         $scaleMax = round($range * 0.05 + $scaleMax);
         if ($scaleMin < 0) {
             $scaleMin = $scaleMin - round($range * 0.05);
         }
         $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
     } else {
         if ($barexists || $overlayexists) {
             $scaleMin = "Unknown";
             $scaleMax = 0;
             $min = false;
             $max = false;
             foreach ($this->plot as $k => $v) {
                 if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") {
                     $series = $v["name"] . $k;
                     minmaxValueOfSeries($v["data"], $min, $max);
                     if ($scaleMin == "Unknown" || $min < $scaleMin) {
                         $scaleMin = $min;
                     }
                     if ($scaleMax == "Unknown" || $max > $scaleMax) {
                         $scaleMax = $max;
                     }
                 }
             }
             if ($scaleMin > 0) {
                 $scaleMin = 0;
             }
             $range = $scaleMax - $scaleMin;
             // Make scales based on 5% of the range of values
             $scaleMax = round($range * 0.05 + $scaleMax);
             if ($scaleMin < 0) {
                 $scaleMin = $scaleMin - round($range * 0.05);
             }
             $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax));
         }
     }
     //echo "<PRE>";
     //var_dump($graphData->GetDataDescription());
     //die;
     // Find out if a scale is required, will be except for pie charts
     $scalerequired = false;
     foreach ($this->plot as $k => $v) {
         switch ($v["type"]) {
             case "BAR":
             case "STACKEDBAR":
             case "OVERLAYBAR":
             case "LINE":
                 $scalerequired = "NORMAL";
                 break;
             case "SCATTER":
                 $scalerequired = "SCATTER";
                 break;
         }
     }
     $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->xtitlefontsize);
     if ($scalerequired) {
         $graphImage->setGraphArea($this->marginleft_actual, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom_actual);
         $graphImage->drawGraphAreaGradient(240, 240, 240, -20);
         // Automatic generation of x tick interval based on number of ticks
         if ($this->xticklabelinterval_actual == "AUTO") {
             $labct = count($this->plot[0]["data"]);
             $this->xticklabelinterval_actual = floor($labct / 35) + 1;
         }
         if ($scalerequired == "NORMAL") {
             $graphImage->drawScale($graphData->GetData(), $graphData->GetDataDescription(), $scale_drawing_mode, 0, 0, 0, TRUE, 40, FALSE, TRUE, $this->xticklabelinterval_actual, FALSE);
         }
         $graphImage->drawGrid(2, TRUE, 230, 230, 230, 45);
     } else {
         $this->marginright = 5;
         $this->marginbottom = 5;
         $this->marginleft = 5;
         $this->marginright_actual = 5;
         $this->marginbottom_actual = 5;
         $this->marginleft_actual = 5;
         //$this->margintop_actual = 5;
         $graphImage->setGraphArea($this->marginleft, $this->margintop_actual, $this->width_pdf_actual - $this->marginright, $this->height_pdf_actual - $this->marginbottom);
         $graphImage->drawGraphAreaGradient(240, 240, 240, -10);
     }
     // If there's a Pie chart we want to draw different legends
     $piechart = false;
     foreach ($this->plot as $k => $v) {
         disableAllSeries($this->plot, $graphData);
         $series = $v["name"] . $k;
         setSerieDrawable($this->plot, $graphData, $series, TRUE);
         switch ($v["type"]) {
             case "PIE":
                 $piedrawn = true;
                 $piechart = true;
                 $graphImage->drawFilledCircle($this->width_pdf_actual / 2 + 2, $this->margintop_actual + 2 + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45 + 1, 200, 200, 200);
                 $graphImage->drawBasicPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.45, PIE_PERCENTAGE_LABEL, 255, 255, 218);
                 break;
             case "PIE3D":
                 $piedrawn = true;
                 $piechart = true;
                 $graphImage->drawPieGraph($graphData->GetData(), $graphData->GetDataDescription(), $this->width_pdf_actual / 2, $this->margintop_actual + ($this->height_pdf_actual - $this->margintop_actual - $this->marginbottom_actual) / 2, ($this->height_pdf_actual - $this->marginbottom_actual - $this->margintop_actual - 20) * 0.5, PIE_PERCENTAGE_LABEL, true, 60, 20, 0, 0);
                 break;
             case "OVERLAYBAR":
             case "STACKEDBAR":
             case "BAR":
                 if ($stackeddrawn) {
                     break;
                 }
                 if ($barexists || $overlayexists) {
                     foreach ($this->plot as $k1 => $v1) {
                         if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR" || $v1["type"] == "OVERLAYBAR") {
                             setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
                         }
                     }
                 }
                 $stackeddrawn = true;
                 if ($stackedexists) {
                     $graphImage->drawStackedBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90);
                 } else {
                     if ($overlayexists) {
                         $graphImage->drawOverlayBarGraph($graphData->GetData(), $graphData->GetDataDescription(), 90);
                     } else {
                         $graphImage->drawBarGraph($graphData->GetData(), $graphData->GetDataDescription());
                     }
                 }
                 break;
             case "SCATTER":
                 if ($scatterdrawn) {
                     break;
                 }
                 $scatterdrawn = true;
                 $series1 = false;
                 $series2 = false;
                 $graphImage->reportWarnings("GD");
                 $ct = 0;
                 foreach ($this->plot as $k1 => $v1) {
                     if ($v1["type"] == "SCATTER") {
                         if ($ct == 0) {
                             $series1 = $v1["name"] . $k1;
                         }
                         if ($ct == 1) {
                             $series2 = $v1["name"] . $k1;
                         }
                         $ct++;
                         setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
                     }
                 }
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $graphImage->drawXYScale($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2, 0, 0, 0);
                 //$graphImage->drawXYGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2);
                 $graphImage->drawXYPlotGraph($graphData->GetData(), $graphData->GetDataDescription(), $series1, $series2);
                 $graphImage->writeValues($graphData->GetData(), $graphData->GetDataDescription(), $series2);
                 break;
             case "LINE":
             default:
                 if ($linedrawn) {
                     break;
                 }
                 $linedrawn = true;
                 foreach ($this->plot as $k1 => $v1) {
                     if ($v1["type"] == "LINE") {
                         setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
                     }
                 }
                 if (count($v["data"]) == 1) {
                     $v["data"][] = 0;
                 }
                 $graphImage->LineWidth = 1;
                 $graphImage->drawLineGraph($graphData->GetData(), $graphData->GetDataDescription());
                 $graphImage->drawPlotGraph($graphData->GetData(), $graphData->GetDataDescription());
                 $graphImage->LineWidth = 1;
                 break;
         }
     }
     foreach ($this->plot as $k1 => $v1) {
         setSerieDrawable($this->plot, $graphData, $v1["name"] . $k1, TRUE);
     }
     // Draw Legend if legend value has been set
     $drawlegend = false;
     foreach ($this->plot as $k => $v) {
         if (isset($v["legend"]) && $v["legend"]) {
             // Temporarily Dont draw legend for Pie
             //if ( $piechart )
             //$graphImage->drawPieLegend($this->width_pdf_actual - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250);
             if (!$piechart) {
                 $graphImage->drawLegend($this->width_pdf_actual - 120, 30, $graphData->GetDataDescription(), 254, 254, 254, 0, 0, 0);
             }
             break;
         }
     }
     $graphImage->setFontProperties(PCHARTFONTS_DIR . $this->xtitlefont, $this->titlefontsize);
     $graphImage->drawTitle(0, 24, $this->title_actual, 50, 50, 50, $this->width_pdf_actual);
     //$graphImage->setShadow(TRUE,array("X"=>0,"Y"=>0,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
     //$graphImage->Render("example.png");
     //$graphImage->Stroke();
     $graphImage->render($outputfile);
     return true;
 }
function knews_drawLine($values, $captions, $filename, $palette = "softtones_pro.txt", $legend = true)
{
    // Dataset definition
    $DataSet = new pData();
    $n = 1;
    foreach ($values as $value_serie) {
        $DataSet->AddPoint($value_serie, "Serie" . $n);
        $DataSet->SetSerieName($captions[$n], "Serie" . $n);
        if ($captions[$n] == '') {
            $DataSet->RemoveSerie("Serie" . $n);
        }
        $DataSet->AddSerie("Serie" . $n);
        $n++;
    }
    //$DataSet->AddAllSeries();
    $DataSet->SetAbsciseLabelSerie("Serie" . ($n - 1));
    $DataSet->SetYAxisName($captions[0]);
    // $DataSet->SetYAxisUnit("u");
    // Initialise the graph
    $Test = new pChart(850, 230);
    $Test->loadColorPalette(KNEWS_DIR . "/includes/pChart/" . $palette);
    $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 8);
    $Test->setGraphArea(60, 20, 820, 200);
    $Test->drawFilledRoundedRectangle(7, 7, 843, 223, 5, 240, 240, 240);
    $Test->drawRoundedRectangle(5, 5, 845, 225, 5, 230, 230, 230);
    $Test->drawGraphArea(255, 255, 255, TRUE);
    $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 2);
    $Test->drawGrid(4, TRUE, 230, 230, 230, 50);
    // Draw the 0 line
    $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 6);
    $Test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
    // Draw the line graph
    $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
    $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
    // Finish the graph
    //$DataSet->RemoveSerie("Serie1");
    $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 8);
    if ($legend) {
        $Test->drawLegend(75, 35, $DataSet->GetDataDescription(), 255, 255, 255);
    }
    $Test->setFontProperties(KNEWS_DIR . "/includes/pChart/tahoma.ttf", 10);
    //$Test->drawTitle(60,22,"example 1",50,50,50,585);
    $Test->Render(KNEWS_DIR . "/tmp/" . $filename);
}
Exemplo n.º 24
0
$DataSet->AddPoint(array("Jan", "Feb", "Mar", "Apr", "May", "Jun"), "Serie3");
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("Company A", "Serie1");
$DataSet->SetSerieName("Company B", "Serie2");
$DataSet->SetYAxisName("Product sales");
$DataSet->SetYAxisUnit("k");
$DataSet->SetSerieSymbol("Serie1", "Sample/Point_Asterisk.gif");
$DataSet->SetSerieSymbol("Serie2", "Sample/Point_Cd.gif");
// Initialise the graph
$Test = new pChart(700, 230);
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->setGraphArea(65, 30, 650, 200);
$Test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
$Test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
$Test->drawGraphArea(255, 255, 255, TRUE);
$Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE);
$Test->drawGrid(4, TRUE, 230, 230, 230, 50);
// Draw the title
$Test->setFontProperties("Fonts/pf_arma_five.ttf", 6);
$Title = "Comparative product sales for company A & B  ";
$Test->drawTextBox(65, 30, 650, 45, $Title, 0, 255, 255, 255, ALIGN_RIGHT, TRUE, 0, 0, 0, 30);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, 255, 255, 255);
// Draw the legend
$Test->setFontProperties("Fonts/tahoma.ttf", 8);
$Test->drawLegend(80, 60, $DataSet->GetDataDescription(), 255, 255, 255);
// Render the chart
$Test->Render("example22.png");
Exemplo n.º 25
0
        default:
            if ($linedrawn) {
                break;
            }
            $linedrawn = true;
            foreach ($plot as $k1 => $v1) {
                if ($v1["type"] == "LINE") {
                    setSerieDrawable($plot, $graphData, $v1["name"] . $k1, TRUE);
                }
            }
            if (count($v["data"]) == 1) {
                $v["data"][] = 0;
            }
            $graphImage->LineWidth = 1;
            $graphImage->drawLineGraph($graphData->GetData(), $graphData->GetDataDescription());
            $graphImage->drawPlotGraph($graphData->GetData(), $graphData->GetDataDescription());
            $graphImage->LineWidth = 1;
            break;
    }
}
foreach ($plot as $k1 => $v1) {
    setSerieDrawable($plot, $graphData, $v1["name"] . $k1, TRUE);
}
// Draw Legend if legend value has been set
$drawlegend = false;
foreach ($plot as $k => $v) {
    if (isset($v["legend"]) && $v["legend"]) {
        // Temporarily Dont draw legend for Pie
        //if ( $piechart )
        //$graphImage->drawPieLegend($width - 180,30,$graphData->GetData(), $graphData->GetDataDescription(), 250, 250, 250);
        if (!$piechart) {
Exemplo n.º 26
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()));
 }
Exemplo n.º 27
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;
    }
Exemplo n.º 28
-1
 function cartesianChart($type, $x, $y, $w, $h, $imgname = '', $config = array())
 {
     $w -= 4;
     $h -= 4;
     $settings = array('FontName' => 'tahoma.ttf', 'FontSize' => 8, 'LegendFontSize' => 8, 'LegendFontName' => 'tahoma.ttf', 'Logo' => '', 'LogoTransparency' => 20, 'XAxisFormat' => 'number', 'XAxisUnit' => '', 'YAxisFormat' => 'number', 'YAxisUnit' => '', 'XLogo' => 0, 'YLogo' => 0, 'Xlabel' => 'x label', 'XAngle' => 0, 'Ylabel' => 'y label', 'Legend' => '', 'Textbox' => '', 'TextboxFontSize' => 8, 'TextboxFontName' => 'tahoma.ttf', 'ImgR' => 132, 'ImgG' => 173, 'ImgB' => 131, 'Decay' => 80, 'BGR' => 163, 'BGG' => 203, 'BGB' => 167, 'Decay2' => 80, 'Filled' => '', 'DataR' => 191, 'DataG' => 120, 'DataB' => 71, 'LBR' => 226, 'LBG' => 228, 'LBB' => 230, 'LR' => 0, 'LG' => 0, 'LB' => 0);
     // Get the custom settings
     if (is_array($config)) {
         foreach ($config as $key => $val) {
             $settings[$key] = $val;
         }
     }
     $DataSet = new pData();
     $DataSet->AddPoint($y, "Serie1");
     $DataSet->AddPoint($x, "Serie2");
     $DataSet->AddAllSeries();
     $DataSet->RemoveSerie("Serie2");
     $DataSet->SetAbsciseLabelSerie("Serie2");
     $DataSet->SetSerieName($settings['Legend'], "Serie1");
     $DataSet->SetYAxisName($settings['Ylabel']);
     $DataSet->SetXAxisName($settings['Xlabel']);
     $DataSet->SetXAxisFormat($settings['XAxisFormat']);
     if (strlen($settings['XAxisUnit'])) {
         $DataSet->SetXAxisUnit($settings['XAxisUnit']);
     }
     if (strlen($settings['YAxisUnit'])) {
         $DataSet->SetYAxisUnit($settings['YAxisUnit']);
     }
     $DataSet->SetYAxisFormat($settings['YAxisFormat']);
     // Initialise the graph
     $Test = new pChart($w, $h);
     $Test->drawGraphAreaGradient($settings['ImgR'], $settings['ImgG'], $settings['ImgB'], $settings['Decay'], TARGET_BACKGROUND);
     $FontSize = $settings['FontSize'];
     $FontName = $this->_ext_path . "/fonts/" . $settings['FontName'];
     $Test->setFontProperties($FontName, $FontSize);
     //Calc Textbox Height
     if (strlen($settings['Textbox'])) {
         $TextboxFontSize = $settings['TextboxFontSize'];
         $TextboxFontName = $this->_ext_path . "/fonts/" . $settings['TextboxFontName'];
         $Position = imageftbbox($TextboxFontSize, 0, $TextboxFontName, $settings['Textbox']);
         $TextboxHeight = $Position[1] - $Position[7] + 8;
     } else {
         $TextboxHeight = 0;
     }
     // Maximize The graph area
     //on Y axis
     if ($settings['XAxisFormat'] == 'time') {
         $xdata = "99:99:99";
         $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
         $WXmax = $Position[2] - $Position[0];
         $TextHeightX = $Position[1] - $Position[7];
     } elseif ($settings['XAxisFormat'] == 'date') {
         $xdata = "99/99/9999";
         $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
         $WXmax = $Position[2] - $Position[0];
         $TextHeightX = $Position[1] - $Position[7];
     } else {
         $WXmax = 0;
         foreach ($x as $xdata) {
             $xdata .= $settings['XAxisUnit'];
             $Position = imageftbbox($FontSize, 0, $FontName, $xdata);
             $TextWidth = $Position[2] - $Position[0];
             $TextHeightX = $Position[1] - $Position[7];
             $WXmax = $TextWidth > $WXmax ? $TextWidth : $WXmax;
         }
     }
     if ($settings['XAngle'] > 0) {
         $sin = abs(sin(deg2rad($settings['XAngle'])));
         $cos = abs(cos(deg2rad($settings['XAngle'])));
         $HXmax = $WXmax * $sin + $TextHeightX * $cos;
     } else {
         $HXmax = $TextHeightX;
     }
     //on Y axis...
     if ($settings['YAxisFormat'] == 'time') {
         $ydata = "99:99:99";
         $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
         $WYmax = $Position[2] - $Position[0];
         $TextHeightY = $Position[1] - $Position[7];
     } elseif ($settings['YAxisFormat'] == 'date') {
         $ydata = "99/99/9999";
         $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
         $WYmax = $Position[2] - $Position[0];
         $TextHeightY = $Position[1] - $Position[7];
     } else {
         $WYmax = 0;
         foreach ($y as $ydata) {
             $ydata .= $settings['YAxisUnit'];
             //echo $ydata."<br>";
             $Position = imageftbbox($FontSize, 0, $FontName, $ydata);
             $TextWidth = $Position[2] - $Position[0];
             $TextHeightY = $Position[1] - $Position[7];
             $WYmax = $TextWidth > $WYmax ? $TextWidth : $WYmax;
         }
     }
     $Test->setGraphArea($WYmax + $TextHeightY + 35, 20, $w - 25, $h - $HXmax - $TextHeightX - $TextboxHeight - 20);
     //$Test->setGraphArea(60,20,$w-25,($settings['XAngle']==0)?$h-70:$h-100);
     $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALL, 213, 217, 221, TRUE, $settings['XAngle'], 0, TRUE);
     $Test->drawGraphAreaGradient($settings['BGR'], $settings['BGG'], $settings['BGB'], $settings['Decay2']);
     $Test->drawGrid(4, TRUE, 230, 230, 230, 20);
     // This will put the picture "logo.png" with transparency
     if (strlen($settings['Logo'])) {
         $XLogo = $WYmax + $TextHeightY + 35 + $settings['XLogo'];
         $YLogo = 20 + $settings['XLogo'];
         $logo = $settings['Logo'];
         //Fing extension of logo : png,gif or jpg
         if ($this->_findexts($logo) == "png") {
             echo "png!";
             $Test->drawFromPNG($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         } elseif ($this->_findexts($logo) == "gif") {
             echo "gif!";
             $Test->drawFromGIF($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         } elseif ($this->_findexts($logo) == "jpg") {
             echo "jpg";
             $Test->drawFromJPG($logo, $XLogo, $YLogo, $settings['LogoTransparency']);
         }
     }
     $Test->setColorPalette(0, $settings['DataR'], $settings['DataG'], $settings['DataB']);
     if ($type == "bar") {
         // Draw the bar chart
         $Test->drawStackedBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 70);
     } elseif ($type == "line") {
         $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
     } elseif ($type == "cubic") {
         $Test->setShadowProperties(3, 3, 0, 0, 0, 30, 4);
         $Test->drawCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription());
         $Test->clearShadow();
         if ($settings['Filled'] == 'yes') {
             $Test->drawFilledCubicCurve($DataSet->GetData(), $DataSet->GetDataDescription(), 0.1, 30);
         }
         $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 0, -1, -1, -1, TRUE);
     }
     // Draw the textbox
     if (strlen($settings['Textbox'])) {
         $Test->setFontProperties($TextboxFontName, $TextboxFontSize);
         $Test->drawTextBox(0, $h - $TextboxHeight, $w, $h, $settings['Textbox'], 0, 255, 255, 255, ALIGN_CENTER, TRUE, 0, 0, 0, 30);
     }
     // Draw the legend
     if (strlen($settings['Legend'])) {
         $LegendFontSize = $settings['LegendFontSize'];
         $LegendFontName = $this->_ext_path . "/fonts/" . $settings['LegendFontName'];
         $Position = imageftbbox($LegendFontSize, 0, $LegendFontName, $settings['Legend']);
         $LegendW = $Position[2] - $Position[0] + 40;
         $Test->setFontProperties($LegendFontName, $LegendFontSize);
         $Test->drawLegend($w - $LegendW, 10, $DataSet->GetDataDescription(), $settings['LBR'], $settings['LBG'], $settings['LBB'], 52, 58, 82, $settings['LR'], $settings['LG'], $settings['LB'], TRUE);
     }
     // Render the picture
     $Test->addBorder(2);
     if (strlen($imgname)) {
         //custom image name
         $imgname = $this->_img_path . "/" . $imgname;
     } else {
         $this->obj->load->helper('string');
         $imgname = $this->_img_path . "/{$type}-" . random_string('alnum', 16) . ".png";
     }
     $Test->Render($imgname);
     return array("name" => '/' . $imgname, "w" => $w + 4, "h" => $h + 4);
 }