Beispiel #1
0
 public function pieChartHamSpam($emails = '', $timespan, $title, $output)
 {
     $ham = $spam = 0;
     $range = $this->getRangeInSeconds($timespan);
     $chart = new PieChart(SIZE_X, SIZE_Y);
     $query = $this->db->query("SELECT COUNT(*) AS SPAM FROM " . TABLE_META . " WHERE {$emails} AND arrived > {$range}");
     if ($query->num_rows > 0) {
         $spam = $query->row['SPAM'];
     }
     $query = $this->db->query("SELECT COUNT(*) AS HAM FROM " . TABLE_META . " WHERE {$emails} AND arrived > {$range}");
     if ($query->num_rows > 0) {
         $ham = $query->row['HAM'];
     }
     if ($ham > $spam) {
         $chart->getPlot()->getPalette()->setPieColor(array(new Color(26, 192, 144), new Color(208, 48, 128)));
     } else {
         $chart->getPlot()->getPalette()->setPieColor(array(new Color(208, 48, 128), new Color(26, 192, 144)));
     }
     $dataSet = new XYDataSet();
     $dataSet->addPoint(new Point("HAM ({$ham})", $ham));
     $dataSet->addPoint(new Point("SPAM ({$spam})", $spam));
     $chart->setDataSet($dataSet);
     $chart->setTitle($title);
     $this->sendOutput($chart, $output);
 }
require_once "{$root}/Function/libchart/classes/libchart.php";
require_once "{$root}/Function/Db.php";
require_once "{$root}/Function/Debug.php";
require_once "{$root}/Function/DataTime.php";
$Stati = GetRows("tab_stato_mch", "", "stato_mch", $db, 1);
/*
	echo "<pre>";
		print_r($Stati);
	echo "</pre>";
*/
//Padding::Padding  ($top, $right, $bottom, $left)
define("ChartPath", "tmp/chart.png");
define("ChartWidth", 1000);
define("ChartHeight", 400);
$chart = new PieChart(ChartWidth, ChartHeight);
$chart->getPlot()->setGraphPadding(new Padding("5", "5", "5", "5"));
$chart->setTitle("Statistiche Magazzino RollOut");
$dataSet = new XYDataSet();
foreach ($Stati as $key => $field) {
    $stat = GetRows("tab_macchine", "id_stato = '" . $field['id_stato_call'] . "'", "", $db, 1, "count(id_macchina) as count");
    /*
    		echo "[Debug]: count stato: ".$stat[0]['count']." <br />";
    */
    $dataSet->addPoint(new Point($field['stato_call'] . " ( " . $stat[0]['count'] . " )", $stat[0]['count']));
}
$chart->setDataSet($dataSet);
$chart->render(ChartPath);
?>


	<img src="<?php 
Beispiel #3
0
function show_page($mode_)
{
    if (isset($_GET['from'])) {
        $t0 = strtotime($_GET['from']);
    } else {
        $t0 = strtotime($mode_->get_default_from());
    }
    if (isset($_GET['to'])) {
        $t1 = strtotime($_GET['to']);
    } else {
        $t1 = time();
    }
    $t0 = $mode_->transform_date($t0);
    $t1 = $mode_->transform_date($t1);
    if ($t0 > $t1) {
        popup_error(_('Error: "from" date is after "to" date, the dates will be reversed'));
        $buf = $t0;
        $t0 = $t1;
        $t1 = $buf;
    }
    if ($t1 > time()) {
        popup_error(_('Error: "to" field is in the future, the current time will be used'));
        $t1 = $mode_->transform_date(time());
    }
    if ($t0 > time()) {
        popup_error(_('Error: "from" field is in the future, the current time will be used'));
        $t0 = $mode_->transform_date(time());
    }
    $t2 = strtotime($mode_->get_next(), $t1);
    /* General system */
    if (!is_writable(TMP_DIR)) {
        popup_error(sprintf(_("%s is not writable"), TMP_DIR));
        page_header();
        echo '<h1>' . _('Reporting') . '</h1>';
        page_footer();
        die;
    }
    list($session_number, $result, $res_server, $end_status, $end_status_by_server) = get_session_history($t0, $t2, $mode_);
    $info2 = get_server_history($t0, $t2, $mode_);
    $chart = new LineChart();
    $chart->getPlot()->setLogoFileName('');
    $dataSet = new XYDataSet();
    $step = max(round(count($result) / MAX_STEPS), 1);
    $step_i = 0;
    foreach ($result as $day => $num) {
        $text = '';
        if ($step_i % $step == 0) {
            $text = $mode_->get_pretty_date($day);
        }
        $step_i++;
        $dataSet->addPoint(new Point($text, $num));
    }
    $chart->setDataSet($dataSet);
    $chart->setTitle(_('Number of launched sessions'));
    $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
    $file_id = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
    $chart->render($tmpfile);
    // Foreach server
    $servers = array();
    foreach ($res_server as $server_id => $value) {
        $servers[$server_id] = array();
        $server = $_SESSION['service']->server_info($server_id);
        if ($server) {
            $servers[$server_id]['name'] = $server->getDisplayName();
        } else {
            $servers[$server_id]['name'] = $server_id;
        }
    }
    if ($session_number > 0) {
        $dataSet = new XYDataSet();
        foreach ($res_server as $server_id => $c) {
            if ($server_id === "") {
                $server_id = _("unknown");
            }
            $tot = 0;
            foreach ($c as $k => $v) {
                $tot += $v;
            }
            $value = $tot * 100 / $session_number;
            $dataSet->addPoint(new Point(str_replace(array('%SERVER%', '%TOTAL%'), array($servers[$server_id]['name'], (int) $tot), ngettext(_('%SERVER% (%TOTAL% session)'), _('%SERVER% (%TOTAL% sessions)'), $value)), $value));
        }
        $chart = new PieChart();
        $chart->getPlot()->setLogoFileName('');
        $chart->setTitle(_('Session repartition'));
        $chart->setDataSet($dataSet);
        $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
        $file_id2 = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
        $chart->render($tmpfile);
        if (count($end_status) > 0) {
            $dataSet = new XYDataSet();
            foreach ($end_status as $status_session => $number_status) {
                $dataSet->addPoint(new Point(str_replace(array('%STATUS%', '%TOTAL%'), array(Session::textEndStatus($status_session), (int) $number_status), ngettext(_('%STATUS% (%TOTAL% session)'), _('%STATUS% (%TOTAL% sessions)'), $number_status)), $number_status));
            }
            $chart = new PieChart();
            $chart->getPlot()->setLogoFileName('');
            $chart->setTitle(_('Session end status'));
            $chart->setDataSet($dataSet);
            $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
            $file_id3 = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
            $chart->render($tmpfile);
        }
    }
    // Foreach server
    foreach ($res_server as $server_id => $value) {
        $chart = new LineChart();
        $chart->getPlot()->setLogoFileName('');
        $dataSet = new XYDataSet();
        $step = max(round(count($value) / MAX_STEPS), 1);
        $step_i = 0;
        foreach ($value 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 launched sessions'));
        $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
        $servers[$server_id]['session_file'] = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
        $chart->render($tmpfile);
        $dataSet = new XYDataSet();
        $end_status2 = array();
        if (array_key_exists($server_id, $end_status_by_server)) {
            $end_status2 = $end_status_by_server[$server_id];
        }
        if (count($end_status2) > 0) {
            foreach ($end_status2 as $status_session => $number_status) {
                $dataSet->addPoint(new Point(str_replace(array('%STATUS%', '%TOTAL%'), array(Session::textEndStatus($status_session), (int) $number_status), ngettext(_('%STATUS% (%TOTAL% session)'), _('%STATUS% (%TOTAL% sessions)'), $number_status)), $number_status));
            }
            $chart = new PieChart();
            $chart->getPlot()->setLogoFileName('');
            $chart->setTitle(_('Session end status'));
            $chart->setDataSet($dataSet);
            $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
            $servers[$server_id]['session_end_status'] = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
            $chart->render($tmpfile);
        }
        if (!isset($info2[$server_id])) {
            continue;
        }
        $dataSet_cpu = new XYDataSet();
        $step = max(round(count($info2[$server_id]['cpu']) / MAX_STEPS), 1);
        $step_i = 0;
        foreach ($info2[$server_id]['cpu'] as $day => $num) {
            $text = $step_i % $step == 0 ? substr($day, -2) : '';
            $step_i++;
            $b = get_avg_value($num);
            $dataSet_cpu->addPoint(new Point($text, $b));
        }
        $chart = new LineChart();
        $chart->getPlot()->setLogoFileName('');
        $chart->setDataSet($dataSet_cpu);
        $chart->setTitle(_('CPU usage'));
        $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
        $servers[$server_id]['cpu_file'] = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
        $chart->render($tmpfile);
        $dataSet_ram = new XYDataSet();
        $step = max(round(count($info2[$server_id]['ram']) / MAX_STEPS), 1);
        $step_i = 0;
        foreach ($info2[$server_id]['ram'] as $day => $num) {
            $text = $step_i % $step == 0 ? substr($day, -2) : '';
            $step_i++;
            $b = get_avg_value($num);
            $dataSet_ram->addPoint(new Point($text, $b));
        }
        $chart = new LineChart();
        $chart->getPlot()->setLogoFileName('');
        $chart->setDataSet($dataSet_ram);
        $chart->setTitle(_('RAM usage'));
        $tmpfile = tempnam(TMP_DIR, REPORT_PREFIX);
        $servers[$server_id]['ram_file'] = substr($tmpfile, strlen(TMP_DIR . '/' . REPORT_PREFIX));
        $chart->render($tmpfile);
    }
    page_header(array('js_files' => array('media/script/lib/calendarpopup/CalendarPopup.js')));
    echo '<h1>' . _('Reporting') . '</h1>';
    echo '<div id="calendar_day_from" style="position: absolute; visibility: hidden; background: white;"></div>';
    echo '<div id="calendar_day_to" style="position: absolute; visibility: hidden; background: white;"></div>';
    echo '<script type="text/javascript" charset="utf-8">';
    echo '  document.write(getCalendarStyles());';
    echo '  var calendar_day_from = new CalendarPopup("calendar_day_from");';
    echo '  calendar_day_from.setReturnFunction(\'func_day_from\');';
    echo '  function func_day_from(y,m,d) {';
    echo '    if (m < 10)';
    echo '      m = \'0\'+m;';
    echo '    if (d < 10)';
    echo '      d = \'0\'+d;';
    echo '    $(\'from\').value = y+\'-\'+m+\'-\'+d;';
    echo '    $(\'anchor_day_from\').innerHTML = $(\'from\').value;';
    echo '  }';
    echo '  var calendar_day_to = new CalendarPopup("calendar_day_to");';
    echo '  calendar_day_to.setReturnFunction(\'func_day_to\');';
    echo '  function func_day_to(y,m,d) {';
    echo '    if (m < 10)';
    echo '      m = \'0\'+m;';
    echo '    if (d < 10)';
    echo '      d = \'0\'+d;';
    echo '    $(\'to\').value = y+\'-\'+m+\'-\'+d;';
    echo '    $(\'anchor_day_to\').innerHTML = $(\'to\').value;';
    echo '    }';
    echo '  Event.observe(window, \'load\', function() {';
    echo '    func_day_from(' . date('Y', $t0) . ', ' . date('m', $t0) . ', ' . date('d', $t0) . ');';
    echo '    func_day_to(' . date('Y', $t1) . ', ' . date('m', $t1) . ', ' . date('d', $t1) . ');';
    echo '  });';
    echo '  function generateReport() {';
    echo '    $(\'from\').value+= \' \'+$(\'hour_from\').value+\':00\';';
    echo '    $(\'to\').value+= \' \'+$(\'hour_to\').value+\':00\';';
    echo '    return true;';
    echo '  }';
    echo '</script>';
    echo '<form onsubmit="return generateReport();">';
    echo '<input id="from" name="from" value="" type="hidden" />';
    echo '<input id="to" name="to" value="" type="hidden" />';
    echo '<strong>' . _('From') . '</strong> ';
    echo '<a href="#" id="anchor_day_from" onclick="calendar_day_from.select($(\'from\'), \'anchor_day_from\'); return false;" >' . date('Y-m-d', $t0) . '</a> ';
    echo '<select id="hour_from">';
    for ($i = 0; $i < 24; $i++) {
        echo '<option value="' . $i . '"';
        if ((int) date('H', $t0) == $i) {
            echo ' selected="selected"';
        }
        echo '>' . $i . ':00</option>';
    }
    echo '</select> ';
    echo '<strong>' . _('to') . '</strong> ';
    echo '<a href="#" id="anchor_day_to" onclick="calendar_day_to.select($(\'to\'), \'anchor_day_to\'); return false;" >' . date('Y-m-d', $t1) . '</a> ';
    echo '<select id="hour_to">';
    for ($i = 0; $i < 24; $i++) {
        echo '<option value="' . $i . '"';
        if ((int) date('H', $t1) == $i) {
            echo ' selected="selected"';
        }
        echo '>' . $i . ':00</option>';
    }
    echo '</select> ';
    echo '<strong>' . _('step') . '</strong>';
    echo '<select name="mode">';
    echo '<option value="minute"';
    if ($mode_->get_value() == 'minute') {
        echo ' selected="selected"';
    }
    echo '>' . ReportMode_minute::get_name() . '</option>';
    echo '<option value="hour"';
    if ($mode_->get_value() == 'hour') {
        echo ' selected="selected"';
    }
    echo '>' . ReportMode_hour::get_name() . '</option>';
    echo '<option value="day"';
    if ($mode_->get_value() == 'day') {
        echo ' selected="selected"';
    }
    echo '>' . ReportMode_day::get_name() . '</option>';
    echo '</select> ';
    echo '<input type="submit" value="' . _('Refresh') . '" />';
    echo '</form>';
    echo '<div>';
    echo '<table><tr><td>';
    echo '<img src="?img=1&file=' . $file_id . '" />';
    echo '</td><td><i>';
    if ($mode_->get_value() == 'day') {
        echo _('Abscissa: day of the month');
    } else {
        if ($mode_->get_value() == 'hour') {
            echo _('Abscissa: hour of the day');
        } else {
            if ($mode_->get_value() == 'minute') {
                echo _('Abscissa: minute of the hour');
            }
        }
    }
    echo '<br/>';
    echo _('Ordinate: number of sessions');
    echo '</i></td></tr>';
    echo '<tr><td>';
    echo '<img src="?img=nb_sessions&mode=' . $mode_->get_value() . '&from=' . date('Y-m-d H:i:s', $t0) . '&to=' . date('Y-m-d H:i:s', $t1) . '" />';
    echo '</td><td><i>';
    if ($mode_->get_value() == 'day') {
        echo _('Abscissa: day of the month');
    } else {
        if ($mode_->get_value() == 'hour') {
            echo _('Abscissa: hour of the day');
        } else {
            if ($mode_->get_value() == 'minute') {
                echo _('Abscissa: minute of the hour');
            }
        }
    }
    echo '<br/>';
    echo _('Ordinate: number of sessions');
    echo '</i></td></tr>';
    echo '</table>';
    if ($session_number > 0) {
        if (isset($file_id2)) {
            echo '<img src="?img=1&file=' . $file_id2 . '" />';
        }
        echo ' ';
        if (isset($file_id3)) {
            echo '<img src="?img=1&file=' . $file_id3 . '" />';
        }
    }
    echo '<form action="session-reporting.php">';
    echo '<input type="hidden" name="search_by[]" value="time" />';
    echo '<input type="hidden" name="from" value="' . $t0 . '" />';
    echo '<input type="hidden" name="to" value="' . $t1 . '" />';
    echo '<input type="submit" value="' . _('See archived sessions in this time range') . '" />';
    echo '</form>';
    foreach ($servers as $server_id => $value) {
        echo '<hr/>';
        echo '<h2>' . _('Server') . ' ' . $value['name'] . '</h2>';
        echo '<table>';
        if (isset($value['session_file'])) {
            echo '<tr><td>';
            echo '<img src="?img=1&file=' . $value['session_file'] . '" />';
            echo '</td><td><i>';
            if ($mode_->get_value() == 'day') {
                echo _('Abscissa: day of the month');
            } else {
                if ($mode_->get_value() == 'hour') {
                    echo _('Abscissa: hour of the day');
                } else {
                    if ($mode_->get_value() == 'minute') {
                        echo _('Abscissa: minute of the hour');
                    }
                }
            }
            echo '<br/>';
            echo _('Ordinate: number of sessions');
            echo '</i></td></tr>';
        }
        if (isset($value['session_end_status'])) {
            echo '<tr><td>';
            echo '<img src="?img=1&file=' . $value['session_end_status'] . '" />';
            echo '</td><td></td></tr>';
        }
        if (isset($value['cpu_file'])) {
            echo '<tr><td>';
            echo '<img src="?img=1&file=' . $value['cpu_file'] . '" />';
            echo '</td><td><i>';
            if ($mode_->get_value() == 'day') {
                echo _('Abscissa: day of the month');
            } else {
                if ($mode_->get_value() == 'hour') {
                    echo _('Abscissa: hour of the day');
                } else {
                    if ($mode_->get_value() == 'minute') {
                        echo _('Abscissa: minute of the hour');
                    }
                }
            }
            echo '<br/>';
            echo _('Ordinate: CPU usage in percent');
            echo '</i></td></tr>';
        }
        if (isset($value['ram_file'])) {
            echo '<tr><td>';
            echo '<img src="?img=1&file=' . $value['ram_file'] . '" />';
            echo '</td><td><i>';
            if ($mode_->get_value() == 'day') {
                echo _('Abscissa: day of the month');
            } else {
                if ($mode_->get_value() == 'hour') {
                    echo _('Abscissa: hour of the day');
                } else {
                    if ($mode_->get_value() == 'minute') {
                        echo _('Abscissa: minute of the hour');
                    }
                }
            }
            echo '<br/>';
            echo _('Ordinate: RAM usage in percent');
            echo '</i></td></tr>';
        }
        echo '</table>';
    }
    echo '</div>';
    page_footer();
    die;
}
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
/**
 * Pie chart demonstration
 *
 */
include "../libchart/classes/libchart.php";
$chart = new PieChart();
$chart->getPlot()->getPalette()->setPieColor(array(new Color(255, 0, 0), new Color(255, 255, 255)));
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Amanita abrupta", 80));
$dataSet->addPoint(new Point("Amanita arocheae", 75));
$dataSet->addPoint(new Point("Clitocybe dealbata", 50));
$dataSet->addPoint(new Point("Cortinarius rubellus", 70));
$dataSet->addPoint(new Point("Gyromitra esculenta", 37));
$dataSet->addPoint(new Point("Lepiota castanea", 37));
$chart->setDataSet($dataSet);
$chart->setTitle("Deadly mushrooms");
$chart->render("generated/pie_chart_color.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 pie chart color demonstration</title>
          <div class="box-header"><i class="fa fa-bar-chart-o"></i><h3 class="box-title">Fréquences des visites d'abonnés, année <?php 
echo $year;
?>
</h3></div>
<div class="box-body">
<?php 
//Initialisation graphique
$chartF = new PieChart(400, 280);
$dataSetF = new XYDataSet();
$row = getStatFrequence($year, $epn);
//debug($row);
$dataSetF->addPoint(new Point("1 à 2 fois par semaine", $row['f1']));
$dataSetF->addPoint(new Point("2 à 3 fois par semaine", $row['f2']));
$dataSetF->addPoint(new Point("+3 fois par semaine", $row['f3']));
$chartF->setDataSet($dataSetF);
$chartF->getPlot()->getPalette()->setPieColor(array(new Color(255, 133, 4), new Color(234, 42, 83), new Color(44, 173, 135)));
$chartF->setTitle("Frequence des visites (" . $year . ") ");
$chartF->render("img/chart/" . $year . "/resa_frequenceSemaine_" . $namepn . ".png");
?>
<img src="img/chart/<?php 
echo $year;
?>
/resa_frequenceSemaine_<?php 
echo $namepn;
?>
.png" >
        </div><!-- /.box-body-->
    </div><!-- /.box -->

<!-- Classement des réservations : les adhérents par classe d'âge-->
<div class="box box-primary">
Beispiel #6
0
    // assume year has always 4 digits
    // e.g. 2005
    $curTimestamp = substr($curTimestamp, 0, 4);
    // $curTimestamp is oldest year, if $oldestYear is not set
    if (strlen($oldestYear) === 0) {
        $oldestYear = $curTimestamp;
    }
    if (!isset($matches[$curTimestamp]['year'])) {
        $matches[$curTimestamp]['year'] = $curTimestamp;
    }
    if (strcmp($curTimestamp, $oldTimestamp) === 0) {
        // if we are still in the same month: 1 more match in the month
        $matches[$curTimestamp]['matches']++;
    } else {
        // otherwise initialise with 1 (at least one match at that month)
        $matches[$curTimestamp]['matches'] = '1';
    }
    // done with this month
    $oldTimestamp = $curTimestamp;
}
$chart = new PieChart(450, 250);
$dataSet = new XYDataSet();
$chart->getPlot()->setGraphPadding(new Padding(0, 15, 15, 50));
// add a data point for each month
foreach ($matches as $matchesPerYear) {
    $dataSet->addPoint(new Point($matchesPerYear['year'], $matchesPerYear['matches']));
}
$chart->setDataSet($dataSet);
$chart->setTitle('Official GU Matches [ ' . $oldestYear . ' - ' . date('Y') . ' ]');
// FIXME: Where should the graph be saved?
$chart->render(dirname(__FILE__) . '/img/yearPie.png');
//ateliers
$chartA = new PieChart(400, 280);
$dataSetA = new XYDataSet();
$dataSetA->addPoint(new Point("Présences", $nbpresentatelier));
$dataSetA->addPoint(new Point("Absences", $nbabsentatelier));
$chartA->setDataSet($dataSetA);
$chartA->getPlot()->getPalette()->setPieColor(array(new Color(44, 173, 135), new Color(234, 42, 83)));
$chartA->setTitle("Taux de présence aux ateliers (" . $year . ") ");
$chartA->render("img/chart/" . $year . "/txpresencea_" . $id_user . ".png");
//sessions
$chartS = new PieChart(400, 280);
$dataSetS = new XYDataSet();
$dataSetS->addPoint(new Point("Présences", $nbpresentsession));
$dataSetS->addPoint(new Point("Absences", $nbabsentsession));
$chartS->setDataSet($dataSetS);
$chartS->getPlot()->getPalette()->setPieColor(array(new Color(44, 173, 135), new Color(234, 42, 83)));
$chartS->setTitle("Taux de présence aux session (" . $year . ") ");
$chartS->render("img/chart/" . $year . "/txpresences_" . $id_user . ".png");
?>
<img src="img/chart/<?php 
echo $year;
?>
/txpresencea_<?php 
echo $id_user;
?>
.png" >
<img src="img/chart/<?php 
echo $year;
?>
/txpresences_<?php 
echo $id_user;