Example #1
1
function grafico($v, $nomegraph, $titolo, $x, $upper = Null)
{
    #	$chart = new VerticalBarChart(800,200);
    $chart = new LineChart(700, 245);
    //	var_dump($x);
    $ii = 0;
    $serie = array();
    //	echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><br>";
    foreach ($v as $s) {
        //		var_dump($s);
        //		echo "<br>";
        $serie[$ii] = new XYDataSet();
        $nome_serie[] = $s[0];
        //		echo $s[0]."<br>";
        //		unset($s[0]);
        $flag = True;
        $i = 0;
        $ib = 0;
        foreach ($s as $e) {
            if (!$flag) {
                # per saltare il primo elemento
                //			var_dump($e+0.0);
                while ($ib < $x[$i]) {
                    $serie[$ii]->addPoint(new Point(sprintf("%02d", $ib), 0.0));
                    $ib = $ib + 1;
                }
                $serie[$ii]->addPoint(new Point(sprintf("%02d", $x[$i]), $e + 0.0));
                //				echo "i=",$i,"x=",$x[$i],"ib=",$ib."<br>";
                $ib = $ib + 1;
                $i = $i + 1;
            }
            $flag = False;
        }
        $ii = $ii + 1;
    }
    $ii = 0;
    $dataSet = new XYSeriesDataSet();
    foreach ($serie as $ds) {
        $dataSet->addSerie($nome_serie[$ii], $ds);
        $ii = $ii + 1;
    }
    if ($upper) {
        //		echo "Set massimo valore",$upper,"<br>";
        $chart->setUpper($upper);
        //solo con LineChar()
        $chart->setLower(0.0);
        //solo con LineChar()
    }
    $chart->setDataSet($dataSet);
    $chart->setTitle($titolo);
    $chart->render($nomegraph);
}
 public function display()
 {
     $chart = new LineChart(4500, 350);
     $dataSet = new XYDataSet();
     foreach ($this->data as $key => $datum) {
         $dataSet->addPoint(new Point($datum['client_ip'], $datum['frequency']));
     }
     $chart->setDataSet($dataSet);
     $chart->setTitle("Client Request Frequency Line Plot");
     $chart->render("front-end/images/client_request_vertical_bar_plot.png");
     $session = SessionFactory::create();
     $dom = DOMHandlerFactory::create();
     $dom->setDocumentFromFile(STATISTICAL_LOG_ANALIZER_HTML)->whereIdIs('login-user')->insertNode($session->get('session-user-name'));
     $graph = '<div style="text-align: center;">
                 <img src="front-end/images/client_request_vertical_bar_plot.png" alt="" border="0">
                 </div>';
     $dom->whereIdIs("squidDataContainer")->insertNode($graph);
     $dom->display();
 }
 public function display()
 {
     $session = SessionFactory::create();
     $clientIp = $session->get("selected-client-ip");
     $date = $session->get("selected-date");
     $beginTime = $this->data[0]['time'];
     $endTime = end($this->data)['time'];
     /*CHART*/
     // $chart = new HorizontalBarChart(800,30000);
     $chart = new LineChart(3000, 500);
     $dataSet = new XYDataSet();
     // $protocols = array('http://', 'https://', 'ftp://', 'www.');
     foreach ($this->data as $key => $datum) {
         // $domain = explode('/', str_replace($protocols, '', $datum['url']));
         $dataSet->addPoint(new Point("", $datum['frequency']));
     }
     $chart->setDataSet($dataSet);
     $chart->getPlot()->setGraphPadding(new Padding(5, 3, 20, 140));
     $chart->getPlot()->setLogoFileName("");
     //clear the image logo
     $chart->setTitle("");
     //clear the image title
     $chart->render("front-end/images/domains_request_horizontal_bar_plot.png");
     /*CHART*/
     $session = SessionFactory::create();
     $dom = DOMHandlerFactory::create();
     $dom->setDocumentFromFile(STATISTICAL_LOG_ANALIZER_HTML)->whereIdIs('login-user')->insertNode($session->get('session-user-name'));
     //INSERT TITLE:
     $title = "<h3>Client (" . $clientIp . ") Domains Request Frequency Bar Plot, at: " . $date . " between: " . $beginTime . " and " . $endTime . "</h3>";
     $dom->whereIdIs("body-title")->insertNode($title);
     $graph = '<div style="text-align: center;">
     			<img 
     				src="front-end/images/domains_request_horizontal_bar_plot.png" 
     				alt="" border="0">
     			</div>';
     $dom->whereIdIs("squidDataContainer")->insertNode($graph);
     $dom->display();
 }
Example #4
0
function renderLineChart($value_arrays, $labels = NULL, $title = '', $xlabels = NULL)
{
    $chart = new LineChart(1000, 400);
    $dataSet = new XYSeriesDataSet();
    for ($va = 0; $va < sizeof($value_arrays); $va++) {
        $value_array = $value_arrays[$va];
        $ds = new XYDataSet();
        if (sizeof($value_array)) {
            for ($x = 0; $x < sizeof($value_array); $x++) {
                if ($xlabels) {
                    $label = $xlabels[$x];
                } else {
                    $label = $x + 1;
                }
                $ds->addPoint(new Point($label, $value_array[$x]));
            }
        } else {
            // need at least one point or will except
            $ds->addPoint(new Point(1, 0));
        }
        if ($labels) {
            $label = $labels[$va];
        } else {
            $label = $va;
        }
        $dataSet->addSerie($label, $ds);
    }
    $chart->setDataSet($dataSet);
    $chart->setTitle($title);
    $name = tempnam('/tmp', '.png');
    $chart->render($name);
    $image = base64_encode(file_get_contents($name));
    unlink($name);
    echo '<div style="text-align: center"><img src="data:image/png;base64,';
    echo $image;
    echo '"></div>';
}
 public function display()
 {
     $session = SessionFactory::create();
     $clientIp = $session->get("selected-client-ip");
     $date = $session->get("selected-date");
     $beginTime = $this->data[0]['time'];
     $endTime = end($this->data)['time'];
     /*CHART*/
     $chart = new LineChart(1400, 500);
     $serie1 = new XYDataSet();
     foreach ($this->data as $key => $datum) {
         $serie1->addPoint(new Point("", $datum['client_data']));
     }
     $dataSet = new XYSeriesDataSet();
     $dataSet->addSerie("Client: " . $clientIp . " at " . $date, $serie1);
     $chart->setDataSet($dataSet);
     $chart->getPlot()->setGraphPadding(new Padding(5, 3, 20, 140));
     $chart->setTitle("");
     //clear the image title
     $chart->getPlot()->setLogoFileName("");
     //clear the image logo
     $chart->render("front-end/images/client_data_line_plot.png");
     /*CHART*/
     //DOM:
     $dom = DOMHandlerFactory::create();
     $dom->setDocumentFromFile(STATISTICAL_LOG_ANALIZER_HTML)->whereIdIs('login-user')->insertNode($session->get('session-user-name'));
     //INSERT TITLE:
     $title = "<h3>Client (" . $clientIp . ") Data Consumption Line Chart, \n                            at: " . $date . " between: " . $beginTime . " and " . $endTime . "</h3>";
     $dom->whereIdIs("body-title")->insertNode($title);
     //INSERT GRAPH:
     $graph = '<div style="text-align: center;">
                 <img src="front-end/images/client_data_line_plot.png" alt="" border="0">
                 </div>';
     $dom->whereIdIs("squidDataContainer")->insertNode($graph);
     $dom->display();
 }
 public function printActivityPerWeek()
 {
     $db_query = "SELECT COUNT(command) AS count, EXTRACT(week from timestamp) AS week, EXTRACT(year from timestamp) AS year,\n          to_date('' || EXTRACT(week from timestamp) || ' ' || EXTRACT(year from timestamp), 'IW IYYY') AS date\n          FROM connections\n          WHERE command <> ''\n          GROUP BY week, year\n          ORDER BY week ASC";
     $rows = R::getAll($db_query);
     if (count($rows)) {
         //We create a new line chart and initialize the dataset
         $chart = new LineChart(600, 300);
         $dataSet = new XYDataSet();
         //This graph gets messed up for large DBs, so here is a simple way to limit some of the input
         $counter = 1;
         //Display date legend only every $mod rows, 25 distinct values being the optimal for a graph
         $mod = round(count($rows) / 25);
         if ($mod == 0) {
             $mod = 1;
         }
         //otherwise a division by zero might happen below
         //For every row returned from the database we add a new point to the dataset
         foreach ($rows as $row) {
             if ($counter % $mod == 0) {
                 $dataSet->addPoint(new Point(date('d-m-Y', strtotime($row['date'])), $row['count']));
             } else {
                 $dataSet->addPoint(new Point('', $row['count']));
             }
             $counter++;
             //We add 6 "empty" points to make a horizontal line representing a week
             for ($i = 0; $i < 6; $i++) {
                 $dataSet->addPoint(new Point('', $row['count']));
             }
         }
         //We set the line chart's dataset and render the graph
         $chart->setDataSet($dataSet);
         $chart->setTitle(ACTIVITY_PER_WEEK);
         $chart->render("generated-graphs/shellshock_activity_per_week.png");
         echo '<p>The following line chart visualizes shellshock commands activity per week, by counting the number of input commands to the system for each day of operation.</p>';
         echo '<img src="generated-graphs/shellshock_activity_per_week.png">';
         echo '<br /><hr /><br />';
     }
 }
 /**
  * Función que genera las gráficas con el promedio de errores y
  * violaciones cometidas por los alumnos. Van a mostrarse en el
  * panel del profesor.
  * 
  */
 public function generarGraficaLineaPromedioErroresUnitariosViolaciones()
 {
     $chart = new \LineChart(800, 350);
     $serie_violaciones = new \XYDataSet();
     $serie_errores = new \XYDataSet();
     $num_alumnos_por_intento = array();
     $alumnos_tabla = TableRegistry::get("Alumnos");
     $alumnos = $alumnos_tabla->find('all');
     $intento_realizado = false;
     foreach ($alumnos as $alumno) {
         $intentos_tabla = TableRegistry::get("Intentos");
         $intentos = $intentos_tabla->find('all')->where(['tarea_id' => $_SESSION["lti_idTarea"], 'alumno_id' => $alumno->id]);
         foreach ($intentos as $intento) {
             $intento_realizado = true;
             $clave = "Intento " . $intento->numero_intento;
             if (array_key_exists($clave, $num_alumnos_por_intento)) {
                 $num_alumnos_por_intento[$clave] += 1;
             } else {
                 $num_alumnos_por_intento[$clave] = 1;
             }
             // Violaciones
             $violaciones_tabla = TableRegistry::get("Violaciones");
             $query = $violaciones_tabla->find('all')->where(['intento_id' => $intento->id])->toArray();
             $num_violaciones = count($query);
             $point_violacion = $serie_violaciones->getPointWithX($clave);
             if ($point_violacion != null) {
                 $point_violacion->setY(($point_violacion->getY() + $num_violaciones) / $num_alumnos_por_intento[$clave]);
             } else {
                 $serie_violaciones->addPoint(new \Point($clave, $num_violaciones));
             }
             // Errores
             $errores_tabla = TableRegistry::get("Errores");
             $query = $errores_tabla->find('all')->where(['intento_id' => $intento->id])->toArray();
             $num_errores = count($query);
             $point_error = $serie_errores->getPointWithX($clave);
             if ($point_error != null) {
                 $point_error->setY(($point_error->getY() + $num_errores) / $num_alumnos_por_intento[$clave]);
             } else {
                 $serie_errores->addPoint(new \Point($clave, $num_errores));
             }
         }
     }
     if ($intento_realizado) {
         $dataSet = new \XYSeriesDataSet();
         $dataSet->addSerie("Violaciones de código", $serie_violaciones);
         $dataSet->addSerie("Errores unitarios", $serie_errores);
         $chart->setDataSet($dataSet);
         $chart->setTitle("Promedio de la clase de Violaciones-Errores por intento realizado");
         $chart->render("img/" . $_SESSION["lti_idTarea"] . "-prof-promedioViolacionesErrores.png");
     }
 }
 public function printHumanActivityPerWeek()
 {
     $db_query = "SELECT COUNT(input), MAKEDATE(\n          CASE\n          WHEN WEEKOFYEAR(timestamp) = 52\n          THEN YEAR(timestamp)-1\n          ELSE YEAR(timestamp)\n          END, (WEEKOFYEAR(timestamp) * 7)-4) AS DateOfWeek_Value\n          FROM input\n          GROUP BY WEEKOFYEAR(timestamp)\n          ORDER BY timestamp ASC";
     $rows = R::getAll($db_query);
     if (count($rows)) {
         //We create a new line chart and initialize the dataset
         $chart = new LineChart(600, 300);
         $dataSet = new XYDataSet();
         //This graph gets messed up for large DBs, so here is a simple way to limit some of the input
         $counter = 1;
         //Display date legend only every $mod rows, 25 distinct values being the optimal for a graph
         $mod = round(count($rows) / 25);
         if ($mod == 0) {
             $mod = 1;
         }
         //otherwise a division by zero might happen below
         //For every row returned from the database we add a new point to the dataset
         foreach ($rows as $row) {
             if ($counter % $mod == 0) {
                 $dataSet->addPoint(new Point(date('d-m-Y', strtotime($row['DateOfWeek_Value'])), $row['COUNT(input)']));
             } else {
                 $dataSet->addPoint(new Point('', $row['COUNT(input)']));
             }
             $counter++;
             //We add 6 "empty" points to make a horizontal line representing a week
             for ($i = 0; $i < 6; $i++) {
                 $dataSet->addPoint(new Point('', $row['COUNT(input)']));
             }
         }
         //We set the line chart's dataset and render the graph
         $chart->setDataSet($dataSet);
         $chart->setTitle(HUMAN_ACTIVITY_PER_WEEK);
         $chart->render(DIR_ROOT . "/generated-graphs/human_activity_per_week.png");
         echo '<p>The following line chart visualizes real human activity per week, by counting the number of input to the system for each day of operation.</p>';
         echo '<img src="generated-graphs/human_activity_per_week.png">';
         echo '<br /><hr /><br />';
     }
 }
    $serie3->addPoint(new Point(getMonth($i), $nbTr3));
    $row2 = getStatHeureTypeAbo($year, $i);
    $hparm = ceil($row2 * 100 / 56160);
    echo '<tr>
			<td>' . getMonth($i) . '</td>
            <td>' . $nbTr1 . '</td>
            <td>' . $nbTr2 . '</td>
            <td>' . $nbTr3 . '</td>
			
			<td>' . $hparm . ' %</td></tr>';
}
///Creation du graphique
$dataSetCA->addSerie("Enfants", $serie1);
$dataSetCA->addSerie("Adolescents", $serie2);
$dataSetCA->addSerie("Adultes", $serie3);
$chartCA->setDataSet($dataSetCA);
$chartCA->setTitle("Frequence des reservations par age (" . $year . ")");
$chartCA->getPlot()->setGraphCaptionRatio(0.62);
$chartCA->getPlot()->getPalette()->setLineColor(array(new Color(2, 119, 158), new Color(190, 128, 255), new Color(255, 84, 143)));
$chartCA->render("img/chart/" . $year . "/frequenceParAge.png");
?>




</tbody></table>
</div><div class="box-body">
<img src="img/chart/<?php 
echo $year;
?>
/frequenceParAge.png" width="420px" >
 public function createProbesPerWeek()
 {
     $db_query = "SELECT COUNT(session),\n          MAKEDATE(CASE WHEN WEEKOFYEAR(timestamp) = 52\n            THEN YEAR(timestamp)-1\n            ELSE YEAR(timestamp)\n            END, (WEEKOFYEAR(timestamp) * 7)-4) AS DateOfWeek_Value\n          FROM auth\n          GROUP BY WEEKOFYEAR(timestamp)\n          ORDER BY timestamp ASC";
     $rows = R::getAll($db_query);
     if (count($rows)) {
         //We create a new line chart and initialize the dataset
         $chart = new LineChart(600, 300);
         $dataSet = new XYDataSet();
         //This graph gets messed up for large DBs, so here is a simple way to limit some of the input
         $counter = 1;
         //Display date legend only every $mod rows, 25 distinct values being the optimal for a graph
         $mod = round(count($rows) / 25);
         if ($mod == 0) {
             $mod = 1;
         }
         //otherwise a division by zero might happen below
         //For every row returned from the database we add a new point to the dataset
         foreach ($rows as $row) {
             if ($counter % $mod == 0) {
                 $dataSet->addPoint(new Point(date('d-m-Y', strtotime($row['DateOfWeek_Value'])), $row['COUNT(session)']));
             } else {
                 $dataSet->addPoint(new Point('', $row['COUNT(session)']));
             }
             $counter++;
             //We add 6 "empty" points to make a horizontal line representing a week
             for ($i = 0; $i < 6; $i++) {
                 $dataSet->addPoint(new Point('', $row['COUNT(session)']));
             }
         }
         //We set the line chart's dataset and render the graph
         $chart->setDataSet($dataSet);
         $chart->setTitle(PROBES_PER_WEEK);
         $chart->render(DIR_ROOT . "/generated-graphs/probes_per_week.png");
     }
 }
$serie4->addPoint(new Point("06-05", 800));
$serie4->addPoint(new Point("06-06", 1000));
$serie5 = new XYDataSet();
$serie5->addPoint(new Point("06-01", 380));
$serie5->addPoint(new Point("06-02", 600));
$serie5->addPoint(new Point("06-03", 712));
$serie5->addPoint(new Point("06-04", 842));
$serie5->addPoint(new Point("06-05", 900));
$serie5->addPoint(new Point("06-06", 1200));
$dataSet = new XYSeriesDataSet();
$dataSet->addSerie("Product 1", $serie1);
$dataSet->addSerie("Product 2", $serie2);
$dataSet->addSerie("Product 3", $serie3);
$dataSet->addSerie("Product 4", $serie4);
$dataSet->addSerie("Product 5", $serie5);
$chart->setDataSet($dataSet);
$chart->setTitle("Sales for 2006");
$chart->getPlot()->setGraphCaptionRatio(0.62);
$chart->render("generated/demo6.png");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Libchart line demonstration</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
</head>
<body>
	<img alt="Line chart" src="generated/demo6.png" style="border: 1px solid gray;"/>
</body>
</html>
Example #12
-1
 public function lineChartHamSpam($timespan, $title, $size_x, $size_y, $output)
 {
     $ydata = array();
     $ydata2 = array();
     $dates = array();
     $session = Registry::get('session');
     $chart = new LineChart($size_x, $size_y);
     $chart->getPlot()->getPalette()->setLineColor(array(new Color(208, 48, 128)));
     $line1 = new XYDataSet();
     $limit = $this->getDataPoints($timespan);
     $range = $this->getRangeInSeconds($timespan);
     if ($timespan == "daily") {
         $grouping = "GROUP BY FROM_UNIXTIME(ts, '%Y.%m.%d. %H')";
     } else {
         $grouping = "GROUP BY FROM_UNIXTIME(ts, '%Y.%m.%d.')";
     }
     if ($timespan == "daily") {
         $delta = 3600;
         $date_format = "H:i";
     } else {
         $delta = 86400;
         $date_format = "m.d.";
     }
     if (Registry::get('admin_user') == 0) {
         $q = '';
         $auditdomains = $session->get('auditdomains');
         foreach ($auditdomains as $a) {
             if ($q) {
                 $q .= ",?";
             } else {
                 $q = "?";
             }
         }
         reset($auditdomains);
         $query = $this->db->query("select arrived-(arrived%{$delta}) as ts, count(*) as num from " . VIEW_MESSAGES . " where arrived > {$range} AND todomain IN ({$q}) {$domains} {$grouping} ORDER BY ts DESC limit {$limit}", $auditdomains);
     } else {
         $query = $this->db->query("select arrived-(arrived%{$delta}) as ts, count(*) as num from " . TABLE_META . " where arrived > {$range} {$grouping} ORDER BY ts DESC limit {$limit}");
     }
     foreach ($query->rows as $q) {
         array_push($ydata, $q['num']);
         array_push($dates, date($date_format, $q['ts']));
     }
     if ($query->num_rows >= 15) {
         $i = 0;
         while (list($k, $v) = each($dates)) {
             $i++;
             if ($i % 3) {
                 $dates[$k] = "";
             }
         }
         reset($dates);
     }
     $ydata = array_reverse($ydata);
     $dates = array_reverse($dates);
     for ($i = 0; $i < count($ydata); $i++) {
         $ts = $dates[$i];
         $line1->addPoint(new Point("{$ts}", $ydata[$i]));
     }
     $dataSet = new XYSeriesDataSet();
     $dataSet->addSerie("RCVD", $line1);
     $chart->setDataSet($dataSet);
     $chart->setTitle($title);
     $chart->getPlot()->setGraphCaptionRatio(0.8);
     $this->sendOutput($chart, $output);
 }
Example #13
-1
function show_img_nb_session($mode_)
{
    $ret = getNB_SESSION($mode_);
    // Number of session chart
    $chart = new LineChart();
    $chart->getPlot()->setLogoFileName('');
    $dataSet = new XYDataSet();
    $step = max(round(count($ret) / MAX_STEPS), 1);
    $step_i = 0;
    foreach ($ret as $day => $num) {
        $text = $step_i % $step == 0 ? substr($day, -2) : '';
        $step_i++;
        $dataSet->addPoint(new Point($text, $num));
    }
    $chart->setDataSet($dataSet);
    $chart->setTitle(_('Number of active sessions'));
    header('Content-Type: image/png');
    $chart->render();
    die;
}