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(); }
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(); }
$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>
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); }
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; }
public function createShellshocksPerDay() { $db_query = "SELECT COUNT(connection) AS count, date_trunc('day', timestamp) AS date\n FROM connections\n WHERE is_shellshock = 'true'\n GROUP BY date\n ORDER BY date ASC "; $rows = R::getAll($db_query); if (count($rows)) { //We create a new horizontal bar 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 set the horizontal chart's dataset and render the graph $chart->setDataSet($dataSet); $chart->setTitle(SHELLSHOCK_PER_DAY); $chart->getPlot()->setGraphPadding(new Padding(5, 30, 50, 50)); //top, right, bottom, left | defaults: 5, 30, 50, 50 $chart->render("generated-graphs/shellshocks_per_day.png"); } }
$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" > </div><!-- /.box-body--> </div><!-- /.box -->
// initialise with 1 (at least one match at that hour) $matches[$curTimestamp]['matches'] = '1'; $matches[$curTimestamp]['hours'] = $curTimestamp; } else { // if we are still in the same month: 1 more match in the month $matches[$curTimestamp]['matches']++; } // done with this month $oldTimestamp = $curTimestamp; } // sort matches, beginning with soonest hour of day /* function cmp($a, $b) { if ($a['hours'] == $b['hours']) { return 0; } return ($a['hours'] < $b['hours']) ? -1 : 1; } */ usort($matches, 'cmp'); // $chart = new VerticalBarChart(1400,350); $chart = new LineChart(690, 350); $dataSet = new XYDataSet(); $chart->getPlot()->setGraphPadding(new Padding(5, 25, 10, 25)); // add a data point for each month foreach ($matches as $matchesPerHour) { $dataSet->addPoint(new Point($matchesPerHour['hours'], $matchesPerHour['matches'])); } $chart->setDataSet($dataSet); $chart->setTitle("Official EIE-FF Matches Per Hour [ 01/2005 - 09/2010 ]"); $chart->render("img/matches.per.hour.eie-ff.png");