Ejemplo n.º 1
0
 function monthchart($xdata, $ydata, $title = 'Line Chart')
 {
     // Create the graph. These two calls are always required
     $graph = new Graph(600, 250, "auto", 60);
     $graph->img->SetAntiAliasing(false);
     $graph->SetScale("textlin");
     $graph->xaxis->SetTickLabels($xdata);
     $graph->xgrid->SetColor('#E3E3E3');
     $graph->legend->SetFrameWeight(1);
     // Setup title
     $graph->title->Set($title);
     foreach ($ydata as $item) {
         // Create the linear plot
         if (count($item['values']) != count($xdata)) {
             continue;
         }
         $lineplot = new LinePlot($item['values'], $xdata);
         $lineplot->SetColor($item['color']);
         if (count($ydata) == 1) {
             $lineplot->SetFillColor($item['color']);
         }
         // Add the plot to the graph
         $graph->Add($lineplot);
         $lineplot->SetLegend($item['legend']);
     }
     return $graph;
 }
 /**
  * @return Chart
  */
 public function buildGraph()
 {
     require_once 'common/chart/Chart.class.php';
     if ($this->error == NULL) {
         if ($this->width == 0) {
             $this->width = count($this->data) * self::WIDTH_PER_POINT + self::MARGIN;
         }
         if ($this->scale == GraphOnTrackersV5_Chart_CumulativeFlow::SCALE_DAY) {
             foreach ($this->data as $date => $label) {
                 $dates[] = date('M-d', $date);
             }
         } else {
             foreach ($this->data as $date => $label) {
                 $dates[] = date('M-Y', $date);
             }
         }
         $this->graph = new Chart($this->width, $this->height);
         $colors = $this->getColors();
         $this->graph->SetScale("datlin");
         $this->graph->title->Set($this->title);
         $this->graph->xaxis->SetTickLabels($dates);
         $this->graph->yaxis->scale->SetAutoMin(0);
         if (is_null($this->description)) {
             $this->description = "";
         }
         $this->graph->subtitle->Set($this->description);
         $this->keys = array_keys($this->data[$this->start_date]);
         $this->nbOpt = count($this->keys);
         $this->stackDataCount();
         $this->graph->ygrid->SetFill(true, '#F3FFFF@0.5', '#FFFFFF@0.5');
         for ($i = $this->nbOpt - 1; $i >= 0; $i--) {
             $lineData = array();
             foreach ($this->data as $data => $row) {
                 $lineData[] = $row[$this->keys[$i]];
             }
             $line = new LinePlot($lineData);
             $line->SetFillColor($colors[$this->keys[$i]]);
             $line->SetColor('#000');
             $line->SetLegend($this->keys[$i]);
             $this->graph->Add($line);
         }
         try {
             $legend_line_height = 20;
             $graph_margin_bottom = 70;
             $margin_size = $this->nbOpt * $legend_line_height + $graph_margin_bottom;
             $this->graph->img->SetMargin(70, 30, 30, $margin_size);
         } catch (Exception $e) {
             // do nothing, JPGraph displays the error by itself
         }
         $this->graph->legend->SetAbsPos(0, $this->height, 'left', 'bottom');
     } else {
         $this->graph = $this->error;
     }
     return $this->graph;
 }
Ejemplo n.º 3
0
    }
    // Graphing
    $graph = new Graph(850, 350, 0, false);
    $graph->SetShadow();
    $graph->SetScale("textlin");
    $graph->yaxis->SetTitleMargin(40);
    $graph->img->SetMargin(60, 60, 30, 70);
    $graph->title->Set("MCP Score Distribution");
    $graph->xaxis->title->Set("Score (rounded)");
    $graph->xaxis->SetTextLabelInterval($labelinterval);
    $graph->xaxis->SetTickLabels($data_labels);
    $graph->yaxis->title->Set("No. of messages");
    $graph->legend->SetLayout(LEGEND_HOR);
    $graph->legend->Pos(0.52, 0.87, 'center');
    $bar1 = new LinePlot($data_count);
    $bar1->SetFillColor('blue');
    $graph->Add($bar1);
    $graph->Stroke($filename);
}
// Creating the page
echo "<TABLE BORDER=\"0\" CELLPADDING=\"10\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
echo " <TR><TD ALIGN=\"CENTER\"><IMG SRC=\"" . IMAGES_DIR . MS_LOGO . "\" ALT=\"MailScanner Logo\"></TD></TR>";
echo " <TR>\n";
//  Check Permissions to see if the file has been written and that apache to read it.
if (is_readable($filename)) {
    echo " <TD ALIGN=\"CENTER\"><IMG SRC=\"" . $filename . "\" ALT=\"Graph\"></TD>";
} else {
    echo "<TD ALIGN=\"CENTER\"> File isn't readable. Please make sure that " . CACHE_DIR . " is readable and writable by MailWatch.";
}
// Create the table
echo " </TR>\n";
Ejemplo n.º 4
0
// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_date.php';
// Create a data set in range (50,70) and X-positions
DEFINE('NDATAPOINTS', 360);
DEFINE('SAMPLERATE', 240);
$start = time();
$end = $start + NDATAPOINTS * SAMPLERATE;
$data = array();
$xdata = array();
for ($i = 0; $i < NDATAPOINTS; ++$i) {
    $data[$i] = rand(50, 70);
    $xdata[$i] = $start + $i * SAMPLERATE;
}
// Create the new graph
$graph = new Graph(540, 300);
// Slightly larger than normal margins at the bottom to have room for
// the x-axis labels
$graph->SetMargin(40, 40, 30, 130);
// Fix the Y-scale to go between [0,100] and use date for the x-axis
$graph->SetScale('datlin', 0, 100);
$graph->title->Set("Example on Date scale");
// Set the angle for the labels to 90 degrees
$graph->xaxis->SetLabelAngle(90);
$line = new LinePlot($data, $xdata);
$line->SetLegend('Year 2005');
$line->SetFillColor('lightblue@0.5');
$graph->Add($line);
$graph->Stroke();
Ejemplo n.º 5
0
$graph->yaxis->SetTickSide(SIDE_LEFT);
$graph->y2axis->SetTickSide(SIDE_RIGHT);
$graph->y2axis->SetColor('black', 'blue');
$graph->y2axis->SetLabelFormat('%3d.0%%');
// Create a bar pot
$bplot = new BarPlot($data_freq);
// Create targets and alt texts for the image maps. One for each bar
// (In this example this is just "dummy" targets)
$targ = array("#1", "#2", "#3", "#4", "#5", "#6", "#7");
$alts = array("val=%d", "val=%d", "val=%d", "val=%d", "val=%d", "val=%d", "val=%d");
$bplot->SetCSIMTargets($targ, $alts);
// Create accumulative graph
$lplot = new LinePlot($data_accfreq);
// We want the line plot data point in the middle of the bars
$lplot->SetBarCenter();
// Use transperancy
$lplot->SetFillColor('lightblue@0.6');
$lplot->SetColor('blue@0.6');
//$lplot->SetColor('blue');
$graph->AddY2($lplot);
// Setup the bars
$bplot->SetFillColor("orange@0.2");
$bplot->SetValuePos('center');
$bplot->value->SetFormat("%d");
$bplot->value->SetFont(FF_ARIAL, FS_NORMAL, 9);
$bplot->value->Show();
// Add it to the graph
$graph->Add($bplot);
// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();
Ejemplo n.º 6
0
<?php

// content="text/plain; charset=utf-8"
require_once "jpgraph/jpgraph.php";
require_once "jpgraph/jpgraph_line.php";
$datay = array(1.23, 1.9, 1.6, 3.1, 3.4, 2.8, 2.1, 1.9);
$graph = new Graph(300, 200);
$graph->SetScale('textlin');
$graph->img->SetMargin(40, 40, 40, 40);
$graph->SetShadow();
$graph->title->Set("Example of filled line plot");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$p1 = new LinePlot($datay);
$p1->SetFillColor("orange");
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$graph->Add($p1);
$graph->Stroke();
Ejemplo n.º 7
0
$lineplot = new LinePlot($tot_data, $ticks);
$lineplot->SetLegend('Traffic total');
$lineplot->SetColor('#d5d5d5');
$lineplot->SetFillColor('#d5d5d5@0.5');
// $lineplot2 = new LinePlot($tot_data_inv, $ticks);
// $lineplot2->SetColor("#d5d5d5");
// $lineplot2->SetFillColor("#d5d5d5@0.5");
$lineplot_in = new LinePlot($in_data, $ticks);
$lineplot_in->SetLegend('Traffic In');
$lineplot_in->SetColor('darkgreen');
$lineplot_in->SetFillColor('lightgreen@0.4');
$lineplot_in->SetWeight(1);
$lineplot_out = new LinePlot($out_data_inv, $ticks);
$lineplot_out->SetLegend('Traffic Out');
$lineplot_out->SetColor('darkblue');
$lineplot_out->SetFillColor('lightblue@0.4');
$lineplot_out->SetWeight(1);
if ($_GET['95th']) {
    $lineplot_95th = new LinePlot($per_data, $ticks);
    $lineplot_95th->SetColor('red');
}
if ($_GET['ave']) {
    $lineplot_ave = new LinePlot($ave_data, $ticks);
    $lineplot_ave->SetColor('red');
}
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->Pos(0.52, 0.9, 'center');
$graph->Add($lineplot);
// $graph->Add($lineplot2);
$graph->Add($lineplot_in);
$graph->Add($lineplot_out);
Ejemplo n.º 8
0
$goal1[] = 50000;
// Create the graph. These two calls are always required
$graph = new Graph(600, 350, "auto");
$graph->SetScale("textlin", 0, $goal);
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$top = 25;
$bottom = 85;
$left = 50;
$right = 25;
$graph->img->SetMargin($left, $right, $top, $bottom);
$graph->img->SetImgFormat('png');
$graph->img->SetAntiAliasing();
$goal1p = new LinePlot($goal1);
$goal1p->SetFillColor("#eeffee");
$graph->Add($goal1p);
// Create a bar pot
$bplot = new BarPlot(array_values($days));
$bplot->SetFillColor("#BBBBEE");
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL, FS_NORMAL, 8);
$bplot->value->SetAngle(90);
$bplot->value->SetFormatCallback('number_format');
$graph->Add($bplot);
$txt = new Text("Average / Day: " . number_format($average));
$txt->SetColor("black");
$txt->SetFont(FF_ARIAL, FS_BOLD, 10);
$txt->SetPos(30, 295);
$graph->AddText($txt);
$txt = new Text("30 Day Expected: " . number_format($average * 30));
Ejemplo n.º 9
0
{
    $aVal = date('Y-m-d H:i', $aVal);
}
// Apply this format to all time values in the data to prepare it to be display
array_walk($xdata, 'formatDate');
// Create the graph.
$graph = new Graph(600, 350);
$graph->title->Set('Accumulated values with specified X-axis scale');
$graph->SetScale('textlin');
// Setup margin color
$graph->SetMarginColor('green@0.95');
// Adjust the margin to make room for the X-labels
$graph->SetMargin(40, 30, 40, 120);
// Turn the tick marks out from the plot area
$graph->xaxis->SetTickSide(SIDE_BOTTOM);
$graph->yaxis->SetTickSide(SIDE_LEFT);
$p0 = new LinePlot($ydata[0]);
$p0->SetFillColor('sandybrown');
$p1 = new LinePlot($ydata[1]);
$p1->SetFillColor('lightblue');
$p2 = new LinePlot($ydata[2]);
$p2->SetFillColor('red');
$ap = new AccLinePlot(array($p0, $p1, $p2));
$graph->xaxis->SetTickLabels($xdata);
$graph->xaxis->SetTextLabelInterval(4);
// Add the plot to the graph
$graph->Add($ap);
// Set the angle for the labels to 90 degrees
$graph->xaxis->SetLabelAngle(90);
// Display the graph
$graph->Stroke();
Ejemplo n.º 10
0
function CourbeParHeure($zoom = false)
{
    $day = $_GET["DAY"];
    if ($day == null) {
        $day = date('Y-m-d');
    }
    @mkdir($_GET["BASEPATH"], 0755, true);
    $f_name = "day-global-{$day}.png";
    if ($zoom) {
        $f_name = "day-global-{$day}-zoom.png";
    }
    $fileName = "{$_GET["BASEPATH"]}/{$f_name}";
    if (is_file($fileName)) {
        if (file_get_time_min($fileName) < 20) {
            return "{$_GET["IMGPATH"]}/{$f_name}";
        }
    }
    @unlink($fileName);
    $q = new mysql();
    $sql = "SELECT COUNT(ID) as tcount ,DATE_FORMAT(zDate,'%h') as thour \nFROM `mbx_con`  WHERE DATE_FORMAT(zDate,'%Y-%m-%d')='{$day}' GROUP BY thour ORDER BY thour";
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ydata[] = $ligne["tcount"];
        $xdata[] = $ligne["thour"];
    }
    if (count($ydata) < 2) {
        $ydata[] = 1;
        $xdata[] = date('d');
    }
    $width = 500;
    $height = 200;
    if ($zoom) {
        $width = 720;
        $height = 400;
    }
    $graph = new Graph($width, $height);
    $graph->SetScale('textlin');
    $graph->title->Set("Connexions numbers {$day}");
    $graph->title->SetColor('white');
    $graph->xaxis->title->Set('hours');
    $graph->xaxis->SetTickLabels($xdata);
    $graph->yaxis->title->Set('(connexions)');
    $graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN);
    $graph->SetPlotGradient('black', 'darkred:0.8', 2);
    $graph->xaxis->SetColor('lightgray');
    $graph->yaxis->SetColor('lightgray');
    $graph->xgrid->Show();
    $lineplot = new LinePlot($ydata);
    $lineplot->SetWeight(2);
    $lineplot->SetColor('orange:0.9');
    $lineplot->SetFillColor('white@0.7');
    $lineplot->SetFillFromYMin();
    $lineplot->SetWeight(2);
    $lineplot->SetFilled(true);
    $lineplot->SetFillFromYMin(true);
    $graph->Add($lineplot);
    $gdImgHandler = $graph->Stroke(_IMG_HANDLER);
    $graph->img->Stream($fileName);
    return "{$_GET["IMGPATH"]}/{$f_name}";
}
Ejemplo n.º 11
0
// Now set the tic positions
$graph->xaxis->SetMajTickPositions($tickPositions, $tickLabels);
// Use Times font
$graph->xaxis->SetFont(FF_TIMES, FS_NORMAL, 11);
$graph->yaxis->SetFont(FF_TIMES, FS_NORMAL, 9);
// Set colors for axis
$graph->xaxis->SetColor('lightgray');
$graph->yaxis->SetColor('lightgray');
// Add a X-grid
$graph->xgrid->Show();
// Show ticks outwards
$graph->xaxis->SetTickSide(SIDE_DOWN);
$graph->xaxis->SetLabelMargin(8);
$graph->yaxis->SetTickSide(SIDE_LEFT);
// Setup a filled y-grid
//$graph->ygrid->SetFill(true,'darkgray:1.55@0.7','darkgray:1.6@0.7');
$graph->ygrid->SetStyle('dotted');
$graph->xgrid->SetStyle('dashed');
// Create the plot line
$p1 = new LinePlot($datay, $datax);
$p1->SetWeight(2);
$p1->SetColor('orange:0.9');
$p1->SetFillColor('white@0.7');
$p1->SetFillFromYMin();
$graph->Add($p1);
// Output graph
$graph->Stroke();
?>


Ejemplo n.º 12
0
$graph->tabtitle->SetWidth(TABTITLE_WIDTHFULL);
// Enable X and Y Grid
$graph->xgrid->Show();
$graph->xgrid->SetColor('gray@0.5');
$graph->ygrid->SetColor('gray@0.5');
// Format the legend box
$graph->legend->SetColor('navy');
$graph->legend->SetFillColor('lightgreen');
$graph->legend->SetLineWeight(1);
$graph->legend->SetFont(FF_ARIAL, FS_BOLD, 8);
$graph->legend->SetShadow('gray@0.4', 3);
$graph->legend->SetAbsPos(15, 120, 'right', 'bottom');
// Create the line plots
$p1 = new LinePlot($datay1);
$p1->SetColor("red");
$p1->SetFillColor("yellow@0.5");
$p1->SetWeight(2);
$p1->mark->SetType(MARK_IMG_DIAMOND, 5, 0.6);
$p1->SetLegend('2006');
$graph->Add($p1);
$p2 = new LinePlot($datay2);
$p2->SetColor("darkgreen");
$p2->SetWeight(2);
$p2->SetLegend('2001');
$p2->mark->SetType(MARK_IMG_MBALL, 'red');
$graph->Add($p2);
// Add a vertical line at the end scale position '7'
$l1 = new PlotLine(VERTICAL, 7);
$graph->Add($l1);
// Output the graph
$graph->Stroke();
Ejemplo n.º 13
0
function courbe_today($domain)
{
    $tpl = new templates();
    $q = new mysql();
    $dansguardian_events = "dansguardian_events_" . date('Ym');
    $sql = "SELECT COUNT( ID ) AS tcount, sitename, DATE_FORMAT( zdate, '%H' ) AS thour , DATE_FORMAT( zdate, '%Y-%m-%d' ) AS tday\nFROM {$dansguardian_events}\nWHERE sitename = '{$domain}'\nGROUP BY thour , tday\nHAVING tday = DATE_FORMAT( NOW( ) , '%Y-%m-%d' )\nORDER BY thour";
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $GLOBALS["stats-array-{$domain}"][] = "<tr>\n\t<td style='font-size:12px;font-weight:bold' nowrap>{$ligne["thour"]}:00</td>\n\t<td style='font-size:12px;font-weight:bold' nowrap>{$ligne["tcount"]} hits</td>\n\t</tr>\n\t";
        $ydata[] = $ligne["tcount"];
        $xdata[] = $ligne["hour"];
    }
    $f_name = "day-squid-{$domain}.png";
    $fileName = "ressources/logs/{$f_name}";
    if (is_file($fileName)) {
        if (file_get_time_min($fileName) < 120) {
            return $fileName;
        }
    }
    $title = "{$domain} " . $tpl->_ENGINE_parse_body('{today}');
    @unlink($fileName);
    $width = 500;
    $height = 200;
    if ($zoom) {
        $width = 720;
        $height = 400;
    }
    JpGraphError::SetImageFlag(false);
    $graph = new Graph($width, $height);
    $graph->SetScale('textlin');
    $graph->title->Set($title);
    $graph->title->SetColor('white');
    $graph->xaxis->title->Set('hours');
    $graph->xaxis->SetTickLabels($xdata);
    $graph->yaxis->title->Set('(hits number)');
    $graph->yaxis->scale->SetGrace(10);
    $graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN);
    $graph->SetPlotGradient('black', 'darkred:0.8', 2);
    $graph->SetMargin(55, 20, 60, 20);
    //$graph->img->SetMargin(50,30,30,100);
    $graph->xaxis->SetColor('lightgray');
    $graph->yaxis->SetColor('lightgray');
    $graph->xgrid->Show();
    $lineplot = new LinePlot($ydata);
    $lineplot->SetWeight(2);
    $lineplot->SetColor('orange:0.9');
    $lineplot->SetFillColor('white@0.7');
    $lineplot->SetFillFromYMin();
    $lineplot->SetWeight(2);
    $lineplot->SetFilled(true);
    $lineplot->SetFillFromYMin(true);
    $graph->Add($lineplot);
    JpGraphError::SetImageFlag(false);
    try {
        $gdImgHandler = $graph->Stroke(_IMG_HANDLER);
    } catch (JpGraphException $e) {
        // .. do necessary cleanup
        // Send back error message
        // $e->Stroke();
    }
    $graph->img->Stream($fileName);
    return $fileName;
}
Ejemplo n.º 14
0
$graph->ygrid->SetLineStyle('dashed');
$graph->ygrid->SetColor('gray');
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle('dashed');
$graph->xgrid->SetColor('gray');
// Setup month as labels on the X-axis
$graph->xaxis->SetTickLabels($months);
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->xaxis->SetLabelAngle(45);
// Create a bar pot
$bplot = new BarPlot($ydata);
$bplot->SetWidth(0.6);
$fcol = '#440000';
$tcol = '#FF9090';
$bplot->SetFillGradient($fcol, $tcol, GRAD_LEFT_REFLECTION);
// Set line weigth to 0 so that there are no border
// around each bar
$bplot->SetWeight(0);
$graph->Add($bplot);
// Create filled line plot
$lplot = new LinePlot($ydata2);
$lplot->SetFillColor('skyblue@0.5');
$lplot->SetColor('navy@0.7');
$lplot->SetBarCenter();
$lplot->mark->SetType(MARK_SQUARE);
$lplot->mark->SetColor('blue@0.5');
$lplot->mark->SetFillColor('lightblue');
$lplot->mark->SetSize(6);
$graph->Add($lplot);
// .. and finally send it back to the browser
$graph->Stroke();
Ejemplo n.º 15
0
 function parse($input, $parser)
 {
     global $jpgraphMarkList;
     $chart_type = split(",", $this->type);
     $mark_type = split(",", $this->mark);
     // retrieving data
     $i = 0;
     $max_row_count = -1;
     foreach (split("\n", $input) as $line) {
         // skip empty line or comments
         if (preg_match("/^(\\s*)#.*\$|^(\\s*)\$/", $line)) {
             continue;
         }
         $line_array = split($this->fieldsep, $line);
         // if first loop => setting label and continue with next loop
         if ($i == 0) {
             $this->labels = $line_array;
             $i++;
             continue;
         }
         // Storing data
         for ($j = 0; $j < count($line_array); $j++) {
             $this->datay[$j][] = $line_array[$j];
         }
         // check data integrity
         if ($max_row_count == -1) {
             $max_row_count = count($line_array);
         }
         if ($max_row_count != count($line_array)) {
             throw new Exception("Error while parsing '" . implode($this->fieldsep, $line_array) . "' : bad number of row.");
         }
         $i++;
     }
     $data_start = 0;
     // if(x, y) curve => set datax with first set of datay
     if ($this->islinear) {
         $this->datax = $this->datay[0];
         $data_start = 1;
         if ($this->xistime) {
             for ($i = 0; $i < count($this->datax); $i++) {
                 $this->datax[$i] = strtotime($this->datax[$i]);
             }
         }
     }
     // Setting default value for chart type array. by default : line.
     // If only one type => applying same type for everybody
     if (count($chart_type) == 0) {
         $chart_type[0] = "line";
     }
     if (count($chart_type) != $max_row_count) {
         $tmp_type = $chart_type[0];
         $chart_type = array();
         for ($i = count($chart_type); $i < $max_row_count; $i++) {
             $chart_type[$i] = $tmp_type;
         }
     }
     // same thing for mark
     if (count($mark_type) == 0) {
         $mark_type[0] = "line";
     }
     if (count($mark_type) != $max_row_count) {
         $tmp_mark = $mark_type[0];
         $mark_type = array();
         for ($i = count($mark_type); $i < $max_row_count; $i++) {
             $mark_type[$i] = $tmp_mark;
         }
     }
     // Possibility to ignore data
     $disable_row = array();
     foreach (split(",", $this->disable) as $elt) {
         $disable_row[$elt] = true;
     }
     // Creating data object
     for ($i = $data_start; $i < count($this->datay); $i++) {
         if (array_key_exists($i + 1, $disable_row) && $disable_row[$i + 1]) {
             continue;
         }
         $show_plot = false;
         switch ($chart_type[$i]) {
             case "bar":
                 $plot = new BarPlot($this->datay[$i], $this->datax);
                 $plot->SetWidth($this->barwidth);
                 $plot->SetFillColor($this->color_list[$i % count($this->color_list)]);
                 break;
             case "area":
                 $plot = new LinePlot($this->datay[$i], $this->datax);
                 $plot->SetColor("gray");
                 $plot->SetFillColor($this->color_list[$i % count($this->color_list)]);
                 $show_plot = true;
                 break;
             default:
             case "line":
                 $plot = new LinePlot($this->datay[$i], $this->datax);
                 $show_plot = true;
                 break;
         }
         if ($show_plot) {
             $mark_id = $jpgraphMarkList[$mark_type[$i]];
             if (!$mark_id) {
                 throw new JpgraphMWException("Unknown mark type(" . $mark_type[$i] . "). Possible values are: " . implode(", ", array_keys($jpgraphMarkList)));
             }
             $plot->mark->SetType($mark_id);
             $plot->mark->SetFillColor($this->color_list[$i % count($this->color_list)]);
         }
         $plot->SetLegend($this->labels[$i]);
         if ($this->isstacked) {
             $plot_list[] = $plot;
             $plot->SetColor("black");
             $plot->SetFillColor($this->color_list[$i % count($this->color_list)]);
         } else {
             $plot->SetColor($this->color_list[$i % count($this->color_list)]);
             $this->graph->Add($plot);
         }
     }
     // stacked case
     if ($this->isstacked) {
         $point_area = new AccLinePlot($plot_list);
         $this->graph->Add($point_area);
     }
 }
Ejemplo n.º 16
0
<?php

// content="text/plain; charset=utf-8"
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_error.php';
//$datax = array(3.5,3.7,3,4,6.2,6,3.5,8,14,8,11.1,13.7);
$datay = array(1.23, 1.9, 1.6, 3.1, 3.4, 2.8, 2.1, 1.9);
$graph = new Graph(300, 200);
$graph->img->SetMargin(40, 40, 40, 40);
$graph->img->SetAntiAliasing();
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->title->Set("Example of filled line centered plot");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$p1 = new LinePlot($datay);
$p1->SetFillColor("green");
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$p1->SetColor("blue");
$p1->SetCenter();
$graph->Add($p1);
$graph->Stroke();
?>


Ejemplo n.º 17
0
/**
 * Método que sirve de reemplazo al mecanismo de paloSantoGraph y paloSantoGraphLib
 * para generar gráficos a partir de una clase que devuelve datos.
 *
 * @param   string  $module     Módulo que contiene la clase fuente de datos
 * @param   string  $class      Clase a instanciar para obtener fuente de datos
 * @param   string  $function   Método a llamar en la clase para obtener datos
 * @param   array   $arrParameters  Lista de parámetros para la invocación 
 * @param   string  $functionCB 
 */
function displayGraph($G_MODULE, $G_CLASS, $G_FUNCTION, $G_PARAMETERS, $G_FUNCTIONCB = "")
{
    //------- PARAMETROS DEL GRAPH -------
    $G_TYPE = null;
    //tipo de grafica
    $G_TITLE = null;
    //titulo
    $G_COLOR = null;
    //colores
    $G_LABEL = array();
    //etiquetas
    $G_SIZE = array();
    //tamaño
    $G_MARGIN = array();
    //margen
    $G_LEYEND_NUM_COLUMN = 1;
    $G_LEYEND_POS = array(0.05, 0.5);
    //posicion de las leyendas
    $_MSJ_ERROR = null;
    //$_MSJ_ERROR   = "Sin mensaje ERROR";
    global $_MSJ_NOTHING;
    //$_MSJ_NOTHING = "Sin mensaje NOTHING";
    $G_YDATAS = array();
    $G_ARR_COLOR = array();
    $G_ARR_FILL_COLOR = array();
    $G_ARR_LEYEND = array();
    $G_ARR_STEP = array();
    $G_SHADOW = false;
    $G_LABEL_Y = null;
    //ESTATICOS
    $G_SCALE = "textlin";
    $G_WEIGHT = 1;
    if ($G_MODULE != '') {
        require_once "modules/{$G_MODULE}/libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "modules/{$G_MODULE}/configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConfModule;
        $dsn = isset($arrConfModule["dsn_conn_database"]) ? $arrConfModule["dsn_conn_database"] : "";
    } else {
        require_once "libs/{$G_CLASS}.class.php";
        //lib del modulo
        require_once "configs/default.conf.php";
        //archivo configuracion del modulo
        global $arrConf;
        $dsn = isset($arrConf["dsn_conn_database"]) ? $arrConf["dsn_conn_database"] : "";
    }
    $oPaloClass = new $G_CLASS($dsn);
    $arrParam = $G_PARAMETERS;
    $result = call_user_func_array(array(&$oPaloClass, $G_FUNCTION), $arrParam);
    global $globalCB;
    $globalCB = NULL;
    if ($G_FUNCTIONCB != '') {
        $globalCB = array($oPaloClass, $G_FUNCTIONCB);
    }
    //------------------- CONTRUCCION DEL ARREGLO PARA X & Y -------------------
    global $xData;
    $xData = array();
    $yData = array();
    if (sizeof($result) != 0) {
        $isX_array = false;
        //usado en LINEPLOT, PLOT3D, BARPLOT, LINEPLOT_MULTIAXIS
        foreach ($result as $att => $arrXY) {
            //------------------ ATTRIBUTES ------------------
            if ($att == 'ATTRIBUTES') {
                foreach ($arrXY as $key => $values) {
                    //VARIABLES NECESARIAS
                    if ($key == 'LABEL_X') {
                        $G_LABEL[0] = $values;
                    } else {
                        if ($key == 'LABEL_Y') {
                            $G_LABEL[1] = $values;
                        } else {
                            if ($key == 'TITLE') {
                                $G_TITLE = $values;
                            } else {
                                if ($key == 'TYPE') {
                                    $G_TYPE = $values;
                                } else {
                                    if ($key == 'SIZE') {
                                        $G_SIZE = explode(',', $values);
                                    } else {
                                        if ($key == 'MARGIN') {
                                            $G_MARGIN = explode(',', $values);
                                        } else {
                                            if ($key == 'COLOR') {
                                                $G_COLOR = $values;
                                            } else {
                                                if ($key == 'POS_LEYEND') {
                                                    $G_LEYEND_POS = explode(',', $values);
                                                } else {
                                                    if ($key == 'NUM_COL_LEYEND') {
                                                        $G_LEYEND_NUM_COLUMN = $values;
                                                    } else {
                                                        if ($key == 'SHADOW') {
                                                            $G_SHADOW = $values;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($att == 'MESSAGES') {
                    foreach ($arrXY as $key => $values) {
                        if ($key == 'ERROR') {
                            $_MSJ_ERROR = $values;
                        } else {
                            if ($key == 'NOTHING_SHOW') {
                                $_MSJ_NOTHING = $values;
                            }
                        }
                    }
                } else {
                    if ($att == 'DATA') {
                        foreach ($arrXY as $DAT_N => $MODES) {
                            foreach ($MODES as $key => $values) {
                                /************************************************************/
                                if ($G_TYPE == 'lineplot' || $G_TYPE == 'barplot' || $G_TYPE == 'lineplot_multiaxis') {
                                    if ($key == 'VALUES') {
                                        $yData = array();
                                        foreach ($values as $x => $y) {
                                            if ($isX_array == false) {
                                                $xData[] = $x;
                                            }
                                            $yData[] = $y;
                                        }
                                        $isX_array = is_array($xData) ? true : false;
                                        $G_YDATAS[] = $yData;
                                    } else {
                                        if ($key == 'STYLE') {
                                            foreach ($values as $x => $y) {
                                                if ($x == 'COLOR') {
                                                    $G_ARR_COLOR[] = $y;
                                                } else {
                                                    if ($x == 'LEYEND') {
                                                        $G_ARR_LEYEND[] = $y;
                                                    } else {
                                                        if ($x == 'STYLE_STEP') {
                                                            $G_ARR_STEP[] = $y;
                                                        } else {
                                                            if ($x == 'FILL_COLOR') {
                                                                $G_ARR_FILL_COLOR[] = $y;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if ($G_TYPE == 'plot3d' || $G_TYPE == 'plot3d2') {
                                        if ($key == 'VALUES') {
                                            foreach ($values as $x => $y) {
                                                $yData[] = $y;
                                            }
                                            $G_YDATAS[0] = $yData;
                                        } else {
                                            if ($key == 'STYLE') {
                                                foreach ($values as $x => $y) {
                                                    if ($x == 'COLOR') {
                                                        $G_ARR_COLOR[] = $y;
                                                    } else {
                                                        if ($x == 'LEYEND') {
                                                            $xData[] = $y;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($G_TYPE == 'bar' || $G_TYPE == 'gauge') {
                                            if ($key == 'VALUES') {
                                                foreach ($values as $x => $y) {
                                                    $G_YDATAS[] = $y;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //*****************************************//
    //      ***** ***** ***** ***** *   *      //
    //      *     *   * *   * *   * *   *      //
    //      * *** ***** ***** ***** *****      //
    //      *   * * *   *   * *     *   *      //
    //      ***** *   * *   * *     *   *      //
    //*****************************************//
    // L I N E P L O T
    if (sizeof($G_YDATAS) >= 1) {
        // true no funciona porque cada cadena u otro valor que se retorne es valor "valido o verdadero"
        // y equivale a true, entonces para diferenciarlo verdaderamente se compara con 'true'
        $str = checkAttributes($G_TITLE, $G_TYPE, $G_LABEL_Y, $_MSJ_ERROR, $_MSJ_NOTHING);
        if ($str != 'true') {
            showError($str, $G_SIZE);
            return;
        }
        if ($G_TYPE == 'lineplot') {
            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
            if ($G_SHADOW) {
                $graph->SetShadow();
            }
            $graph->SetScale($G_SCALE);
            $graph->SetMarginColor($G_COLOR);
            $graph->title->Set($G_TITLE);
            $graph->SetFrame(true, '#999999');
            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
            $graph->img->SetAntiAliasing();
            $graph->xaxis->SetLabelFormatCallback("CallBack");
            $graph->xaxis->SetLabelAngle(90);
            $graph->xaxis->title->Set($G_LABEL[0]);
            $graph->yaxis->title->Set($G_LABEL[1]);
            $graph->xgrid->Show();
            $graph->legend->SetFillColor("#fafafa");
            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
            $graph->legend->SetColor("#444444", "#999999");
            $arr_lineplot = array();
            foreach ($G_YDATAS as $num => $yDatas) {
                $lineplot = new LinePlot($yDatas);
                if ($G_ARR_STEP[$num] == true) {
                    $lineplot->SetStepStyle();
                }
                if ($G_ARR_FILL_COLOR[$num] == true) {
                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                }
                $lineplot->SetColor($G_ARR_COLOR[$num]);
                $lineplot->SetWeight($G_WEIGHT);
                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                $arr_lineplot[] = $lineplot;
            }
            foreach ($arr_lineplot as $num => $yDatas) {
                $graph->Add($yDatas);
            }
            if (sizeof($xData) > 100) {
                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
            }
            $graph->Stroke();
        } else {
            if ($G_TYPE == 'plot3d') {
                $graph = new PieGraph($G_SIZE[0], $G_SIZE[1], "auto");
                if ($G_SHADOW) {
                    $graph->SetShadow();
                }
                $dataMarginColor = isset($result["ATTRIBUTES"]["MARGIN_COLOR"]) ? $result["ATTRIBUTES"]["MARGIN_COLOR"] : "#999999";
                $dataSizePie = isset($result["ATTRIBUTES"]["SIZE_PIE"]) ? $result["ATTRIBUTES"]["SIZE_PIE"] : "80";
                $graph->SetMarginColor($G_COLOR);
                $graph->SetFrame(true, $dataMarginColor);
                $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                $graph->legend->SetFillColor("#fafafa");
                $graph->legend->SetColor("#444444", "#999999");
                $graph->legend->SetShadow('gray@0.6', 4);
                $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                $graph->title->Set($G_TITLE);
                $pieplot3d = new PiePlot3d($G_YDATAS[0]);
                $pieplot3d->SetSliceColors($G_ARR_COLOR);
                $pieplot3d->SetCenter(0.4);
                $pieplot3d->SetSize($dataSizePie);
                $pieplot3d->SetAngle(45);
                $pieplot3d->SetStartAngle(45);
                $pieplot3d->value->SetColor('black');
                //color a los porcentages
                $pieplot3d->SetEdge('black');
                //da color al contorno y separacion del pastel
                $pieplot3d->SetLegends($xData);
                $graph->Add($pieplot3d);
                $graph->Stroke();
            } else {
                if ($G_TYPE == 'plot3d2') {
                    if (!function_exists('displayGraph_draw_pie3d')) {
                        function displayGraph_draw_pie3d($canvasx, $ydata, $arrcolor)
                        {
                            $canvasy = $canvasx;
                            $escala = $canvasx / 320.0;
                            $iAnchoPastel = 256 * $escala;
                            $iAltoPastel = 155 * $escala;
                            $iPosCentroX = 141 * $escala;
                            $iPosCentroY = 91 * $escala;
                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasy * 250 / 320);
                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                            imagefill($thumb, 0, 0, $transparent);
                            // Asignar colores de imagen
                            $imgcolor = array();
                            foreach ($arrcolor as $i => $sHtmlColor) {
                                $r = $g = $b = 0;
                                sscanf($sHtmlColor, "#%02x%02x%02x", $r, $g, $b);
                                $imgcolor[$i] = imagecolorallocate($thumb, $r, $g, $b);
                            }
                            $colorTexto = imagecolorallocate($thumb, 0, 0, 0);
                            // Mostrar el gráfico de pastel
                            if (!function_exists('displayGraph_pie')) {
                                function displayGraph_pie($thumb, $x, $y, $w, $h, $ydata, $G_ARR_COLOR, $colorTexto)
                                {
                                    $iTotal = array_sum($ydata);
                                    $iFraccion = 0;
                                    $etiquetas = array();
                                    for ($i = 0; $i < count($ydata); $i++) {
                                        if ($ydata[$i] >= $iTotal) {
                                            imagefilledellipse($thumb, $x, $y, $w, $h, $G_ARR_COLOR[$i]);
                                        } else {
                                            $degInicio = 360 - 45 - (int) (360.0 * ($iFraccion + $ydata[$i]) / $iTotal);
                                            $degFinal = 360 - 45 - (int) (360.0 * $iFraccion / $iTotal);
                                            imagefilledarc($thumb, $x, $y, $w, $h, $degInicio, $degFinal, $G_ARR_COLOR[$i], IMG_ARC_PIE);
                                        }
                                        $iFraccion += $ydata[$i];
                                        $degMitad = ($degInicio + $degFinal) / 2;
                                        $iPosTextoX = $x + 0.5 * ($w / 2.0) * cos(deg2rad($degMitad));
                                        $iPosTextoY = $y + 0.5 * ($h / 2.0) * sin(deg2rad($degMitad));
                                        $etiquetas[] = array($iPosTextoX, $iPosTextoY, sprintf('%.1f %%', 100.0 * $ydata[$i] / $iTotal));
                                    }
                                    /*
                                                            if (!is_null($colorTexto)) {
                                                                for ($i = 0; $i < count($ydata); $i++)
                                                                    imagestring($thumb, 5, $etiquetas[$i][0], $etiquetas[$i][1], $etiquetas[$i][2], $colorTexto);
                                                            }
                                    */
                                }
                            }
                            for ($i = (int) (60 * $escala); $i > 0; $i--) {
                                displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY + $i, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, NULL);
                            }
                            displayGraph_pie($thumb, $iPosCentroX, $iPosCentroY, $iAnchoPastel, $iAltoPastel, $ydata, $imgcolor, $colorTexto);
                            imagealphablending($thumb, true);
                            imagesavealpha($thumb, true);
                            $source2 = imagecreatefrompng("images/pie_alpha.png");
                            imagealphablending($source2, true);
                            imagecopyresampled($thumb, $source2, 0, 0, 0, 0, 290 * $escala, 294 * $escala, 290, 294);
                            header("Content-Type: image/png");
                            imagepng($thumb);
                        }
                    }
                    displayGraph_draw_pie3d($G_SIZE[0], $G_YDATAS[0], $G_ARR_COLOR);
                } else {
                    if ($G_TYPE == 'barplot') {
                        $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                        if ($G_SHADOW) {
                            $graph->SetShadow();
                        }
                        $graph->SetScale($G_SCALE);
                        $graph->SetMarginColor($G_COLOR);
                        $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                        $graph->title->Set($G_TITLE);
                        $graph->xaxis->title->Set($G_LABEL[0]);
                        $graph->xaxis->SetLabelFormatCallback("CallBack");
                        $graph->xaxis->SetLabelAngle(90);
                        //$graph->xaxis->SetTickLabels($xData);
                        $graph->yaxis->title->Set($G_LABEL[1]);
                        $graph->legend->SetFillColor("#fafafa");
                        $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                        $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                        $arr_barplot = array();
                        foreach ($G_YDATAS as $num => $yDatas) {
                            $barplot = new BarPlot($yDatas);
                            $barplot->SetFillColor($G_ARR_COLOR[$num]);
                            $barplot->SetLegend($G_ARR_LEYEND[$num]);
                            $arr_barplot[] = $barplot;
                        }
                        $gbarplot = new GroupBarPlot($arr_barplot);
                        $gbarplot->SetWidth(0.6);
                        $graph->Add($gbarplot);
                        $graph->Stroke();
                    } else {
                        if ($G_TYPE == 'lineplot_multiaxis') {
                            $graph = new Graph($G_SIZE[0], $G_SIZE[1], "auto");
                            if ($G_SHADOW) {
                                $graph->SetShadow();
                            }
                            $inc = sizeof($G_YDATAS);
                            $graph->SetScale($G_SCALE);
                            $graph->SetFrame(true, '#999999');
                            $graph->title->Set($G_TITLE);
                            $graph->img->SetAntiAliasing();
                            $graph->xaxis->SetLabelFormatCallback("CallBack");
                            $graph->img->SetMargin($G_MARGIN[0], $G_MARGIN[1], $G_MARGIN[2], $G_MARGIN[3]);
                            $graph->SetMarginColor($G_COLOR);
                            $graph->legend->SetFillColor("#fafafa");
                            $graph->legend->Pos($G_LEYEND_POS[0], $G_LEYEND_POS[1], "right", "center");
                            $graph->xaxis->SetLabelAngle(90);
                            $graph->legend->SetColor("#444444", "#999999");
                            $graph->legend->SetShadow('gray@0.6', 4);
                            $graph->legend->SetColumns($G_LEYEND_NUM_COLUMN);
                            foreach ($G_YDATAS as $num => $yData) {
                                $lineplot = new LinePlot($yData);
                                $lineplot->SetWeight($G_WEIGHT);
                                $lineplot->SetLegend($G_ARR_LEYEND[$num]);
                                if ($G_ARR_STEP[$num] == true) {
                                    $lineplot->SetStepStyle();
                                }
                                if ($G_ARR_FILL_COLOR[$num] == true) {
                                    $lineplot->SetFillColor($G_ARR_COLOR[$num]);
                                }
                                if ($num == 0) {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->yaxis->SetColor($G_ARR_COLOR[$num]);
                                    $graph->Add($lineplot);
                                } else {
                                    $lineplot->SetColor($G_ARR_COLOR[$num]);
                                    $graph->SetYScale($num - 1, 'lin');
                                    $graph->ynaxis[$num - 1]->SetColor($G_ARR_COLOR[$num]);
                                    $graph->ynaxis[$num - 1]->SetPosAbsDelta($G_MARGIN[1] + 49 * ($num - 1));
                                    //mueve el eje Y
                                    $graph->AddY($num - 1, $lineplot);
                                }
                            }
                            if (sizeof($xData) > 100) {
                                //$graph->xaxis->SetTextLabelInterval( (int)(sizeof($xData)/8) );
                                $graph->xaxis->SetTextTickInterval((int) (sizeof($xData) / 10));
                                //$graph->xaxis->SetTextTickInterval( 9*(int)(log(sizeof($xData))-1) );
                            }
                            $graph->Stroke();
                        } else {
                            if ($G_TYPE == 'bar') {
                                $g = new CanvasGraph(91, 21, 'auto');
                                $g->SetMargin(0, 0, 0, 0);
                                $g->InitFrame();
                                $xmax = 20;
                                $ymax = 20;
                                $scale = new CanvasScale($g);
                                $scale->Set(0, $G_SIZE[0], 0, $G_SIZE[1]);
                                //DUBUJA LA BARRA
                                $alto = $G_SIZE[1];
                                $ancho = $G_SIZE[0];
                                $coor_x = 0;
                                $coor_y = 0;
                                $porcentage = $G_YDATAS[0];
                                $valor = 90 * (1 - $porcentage);
                                $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                for ($i = 0; $i < $alto; $i++) {
                                    $g->img->SetColor(array(95 - 3 * $i, 138 - 3 * $i, 203 - 3 * $i));
                                    //para hacerlo 3D, degradacion
                                    $g->img->Line($coor_x, $coor_y + $i + 1, $coor_x + $ancho - $valor - 1, $coor_y + $i + 1);
                                }
                                $g->Stroke();
                            } else {
                                if ($G_TYPE == 'gauge') {
                                    if (!function_exists('displayGraph_draw_gauge')) {
                                        function displayGraph_draw_gauge($canvasx, $percent)
                                        {
                                            $escala = $canvasx / 320.0;
                                            $thumb = imagecreatetruecolor($canvasx * 284 / 320, $canvasx * 284 / 320);
                                            if ($percent > 100) {
                                                $percent = 100.0;
                                            }
                                            if ($percent < 0) {
                                                $percent = 0.0;
                                            }
                                            $angle = -135.0 + 270 * $percent / 100.0;
                                            // COLORES
                                            $blanco = imagecolorallocate($thumb, 255, 255, 255);
                                            $dred = imagecolorallocate($thumb, 180, 0, 0);
                                            $lred = imagecolorallocate($thumb, 100, 0, 0);
                                            $transparent = imagecolorallocatealpha($thumb, 200, 200, 200, 127);
                                            imagefill($thumb, 0, 0, $transparent);
                                            imagealphablending($thumb, true);
                                            imagesavealpha($thumb, true);
                                            $source = imagecreatefrompng("images/gauge_base.png");
                                            imagealphablending($source, true);
                                            imagecopyresampled($thumb, $source, 0, 0, 0, 0, 285 * $escala, 285 * $escala, 285, 285);
                                            $radius = 100 * $escala;
                                            $radius_min = 12 * $escala;
                                            $centrox = 142 * $escala;
                                            $centroy = 141 * $escala;
                                            $x1 = $centrox + sin(deg2rad($angle)) * $radius;
                                            // x coord farest
                                            $x2 = $centrox + sin(deg2rad($angle - 90)) * $radius_min;
                                            $x3 = $centrox + sin(deg2rad($angle + 90)) * $radius_min;
                                            $y1 = $centroy - cos(deg2rad($angle)) * $radius;
                                            $y2 = $centroy - cos(deg2rad($angle - 90)) * $radius_min;
                                            $y3 = $centroy - cos(deg2rad($angle + 90)) * $radius_min;
                                            $arrTriangle1 = array($centrox, $centroy, $x1, $y1, $x2, $y2);
                                            $arrTriangle2 = array($centrox, $centroy, $x1, $y1, $x3, $y3);
                                            imagefilledpolygon($thumb, $arrTriangle1, 3, $lred);
                                            imagefilledpolygon($thumb, $arrTriangle2, 3, $dred);
                                            $source2 = imagecreatefrompng("images/gauge_center.png");
                                            imagealphablending($source2, true);
                                            imagecopyresampled($thumb, $source2, 121 * $escala, 120 * $escala, 0, 0, 44 * $escala, 44 * $escala, 44, 44);
                                            header("Content-Type: image/png");
                                            imagepng($thumb);
                                        }
                                    }
                                    displayGraph_draw_gauge($G_SIZE[0], $G_YDATAS[0] * 100.0);
                                } else {
                                    if ($G_TYPE == 'bar2') {
                                        $alto = 20;
                                        $ancho = 90;
                                        $coor_x = 100;
                                        $coor_y = 10;
                                        $porcentage = 0.67;
                                        $valor = 90 * (1 - $porcentage);
                                        $g = new CanvasGraph($G_LEN_X, 40, 'auto');
                                        $g->SetMargin(1, 1, 31, 9);
                                        $g->SetMarginColor('#fafafa');
                                        $g->SetColor(array(250, 250, 250));
                                        $g->InitFrame();
                                        $xmax = 20;
                                        $ymax = 20;
                                        $scale = new CanvasScale($g);
                                        $scale->Set(0, $G_LEN_X, 0, $G_LEN_Y);
                                        //DUBUJA LA BARRA
                                        $g->img->Line($coor_x, $coor_y, $coor_x + $ancho, $coor_y);
                                        $g->img->Line($coor_x, $coor_y, $coor_x, $coor_y + $alto);
                                        $g->img->Line($coor_x + $ancho, $coor_y, $coor_x + $ancho, $coor_y + $alto);
                                        $g->img->Line($coor_x, $coor_y + $alto, $coor_x + $ancho, $coor_y + $alto);
                                        for ($i = 0; $i < $alto; $i++) {
                                            $g->img->SetColor(array(95 - 4 * $i, 138 - 4 * $i, 203 - 4 * $i));
                                            //para hacerlo 3D, degradacion
                                            $g->img->Line($coor_x, $coor_y + $i, $coor_x + $ancho - $valor - 1, $coor_y + $i);
                                        }
                                        //AGREGA LABEL 1
                                        $txt = "Uso de CPU";
                                        $t = new Text($txt, 10, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        //AGREGA LABEL 2
                                        $txt = "67.64% used of 2,200.00 MHz";
                                        $t = new Text($txt, 200, 12);
                                        $t->font_style = FS_BOLD;
                                        $t->Stroke($g->img);
                                        $g->Stroke();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        showError('nothing', $G_SIZE, $G_TITLE);
    }
}
Ejemplo n.º 18
0
require_once 'dataset01.inc.php';
$dateUtils = new DateScaleUtils();
// Setup a basic graph
$width = 500;
$height = 300;
$graph = new Graph($width, $height);
$graph->SetScale('datlin');
$graph->SetMargin(60, 20, 40, 60);
// Setup the titles
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 12);
$graph->title->Set('Development since 1984');
$graph->subtitle->SetFont(FF_ARIAL, FS_ITALIC, 10);
$graph->subtitle->Set('(Example using the builtin date scale)');
// Setup the labels to be correctly format on the X-axis
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
$graph->xaxis->SetLabelAngle(30);
// The second paramter set to 'true' will make the library interpret the
// format string as a date format. We use a Month + Year format
// $graph->xaxis->SetLabelFormatString('M, Y',true);
// First add an area plot
$lp1 = new LinePlot($ydata, $xdata);
$lp1->SetWeight(0);
$lp1->SetFillColor('orange@0.85');
$graph->Add($lp1);
// And then add line. We use two plots in order to get a
// more distinct border on the graph
$lp2 = new LinePlot($ydata, $xdata);
$lp2->SetColor('orange');
$graph->Add($lp2);
// And send back to the client
$graph->Stroke();
Ejemplo n.º 19
0
 private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d')
 {
     $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
     $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
     if ($labelCount > 0) {
         $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
         $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
         $this->_graph->xaxis->SetTickLabels($datasetLabels);
     }
     $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
     $seriesPlots = array();
     if ($grouping == 'percentStacked') {
         $sumValues = $this->_percentageSumCalculation($groupID, $seriesCount);
     }
     //	Loop through each data series in turn
     for ($i = 0; $i < $seriesCount; ++$i) {
         $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
         $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
         if ($grouping == 'percentStacked') {
             $dataValues = $this->_percentageAdjustValues($dataValues, $sumValues);
         }
         //	Fill in any missing values in the $dataValues array
         $testCurrentIndex = 0;
         foreach ($dataValues as $k => $dataValue) {
             while ($k != $testCurrentIndex) {
                 $dataValues[$testCurrentIndex] = null;
                 ++$testCurrentIndex;
             }
             ++$testCurrentIndex;
         }
         $seriesPlot = new LinePlot($dataValues);
         if ($combination) {
             $seriesPlot->SetBarCenter();
         }
         if ($filled) {
             $seriesPlot->SetFilled(true);
             $seriesPlot->SetColor('black');
             $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
         } else {
             //	Set the appropriate plot marker
             $this->_formatPointMarker($seriesPlot, $marker);
         }
         $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
         $seriesPlot->SetLegend($dataLabel);
         $seriesPlots[] = $seriesPlot;
     }
     if ($grouping == 'standard') {
         $groupPlot = $seriesPlots;
     } else {
         $groupPlot = new AccLinePlot($seriesPlots);
     }
     $this->_graph->Add($groupPlot);
 }
Ejemplo n.º 20
0
include "../jpgraph_bar.php";
$l1datay = array(11, 9, 2, 4, 3, 13, 17);
$l2datay = array(23, 12, 5, 19, 17, 10, 15);
$datax = array("Jan", "Feb", "Mar", "Apr", "May");
// Create the graph.
$graph = new Graph(400, 200, "auto");
$graph->SetScale("textlin");
$graph->img->SetMargin(40, 130, 20, 40);
$graph->SetShadow();
// Create the linear error plot
$l1plot = new LinePlot($l1datay);
$l1plot->SetColor("red");
$l1plot->SetWeight(2);
$l1plot->SetLegend("Prediction");
// Create the bar plot
$l2plot = new LinePlot($l2datay);
$l2plot->SetFillColor("orange");
$l2plot->SetLegend("Result");
// Add the plots to the graph
$graph->Add($l2plot);
$graph->Add($l1plot);
$graph->title->Set("Mixing line and filled line");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
//$graph->xaxis->SetTickLabels($datax);
//$graph->xaxis->SetTextTickInterval(2);
// Display the graph
$graph->Stroke();
Ejemplo n.º 21
0
$report = new ReportUserAdded($SPAN, $start, $end);
//
//	Check for error, such as license key problem
//
if ($report->isError()) {
    echo $report->getErrorMessage();
    exit;
}
// Some data
$ydata = $report->getData();
// Create the graph. These two calls are always required
$graph = new Graph(640, 480, "auto");
$graph->SetMargin(50, 10, 35, 50);
$graph->SetScale("textlin");
// Create the linear plot
$lineplot = new LinePlot($ydata);
$lineplot->SetColor("black");
$lineplot->SetFillColor("orange");
// Add the plot to the graph
$graph->Add($lineplot);
//$graph->SetMargin(10,10,25,10);
$graph->title->Set("Users Added " . $report->getSpanName() . " (" . date('m/d/Y', $report->getStartDate()) . "-" . date('m/d/Y', $report->getEndDate()) . ")");
$graph->subtitle->Set($sys_name);
//$graph->xaxis-> title->Set("Date" );
//$graph->yaxis-> title->Set("Number" );
$a = $report->getDates();
$graph->xaxis->SetTickLabels($a);
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetTextLabelInterval($report->getGraphInterval());
// Display the graph
$graph->Stroke();
Ejemplo n.º 22
0
$valeur = array();
$moment = array();
$i = 0;
include '../connexion_mysql.php';
$reponse = $bdd->query('SELECT * FROM luminosite');
$i = 0;
while ($donnees = $reponse->fetch()) {
    $valeur[$i] = $donnees['valeur'];
    $moment[$i] = strtotime($donnees['moment']);
    $i = $i + 1;
}
$graph = new Graph(1600, 750);
$graph->SetMargin(65, 10, 55, 130);
$graph->SetScale('datlin');
$graph->title->Set("Evolution de la luminosité depuis le début");
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->SetTitle("Moment", 'middle');
$graph->xaxis->scale->SetDateFormat('d/m/y H:i');
$graph->yaxis->SetTitle("Luminosité (en V)", 'middle');
$graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 16);
$graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 16);
$graph->title->SetFont(FF_ARIAL, FS_BOLD, 32);
$graph->xaxis->SetTitlemargin(90);
$line = new LinePlot($valeur, $moment);
$line->SetFillColor('orange@0.5');
$graph->Add($line);
$graph->Stroke();
?>


Ejemplo n.º 23
0
 function Create(MASK $mask = NULL, INTERVAL $iv = NULL)
 {
     global $GRAPH_MARGINS;
     global $GRAPH_DENSITY_PLOT_VALID_SIZE;
     global $GRAPH_DENSITY_PLOT_VALID_COLOR;
     global $GRAPH_DENSITY_PLOT_INVALID_SIZE;
     global $GRAPH_DENSITY_PLOT_INVALID_COLOR;
     global $GRAPH_DENSITY_POINTS_TYPE;
     global $GRAPH_DENSITY_POINTS_SIZE;
     global $GRAPH_DENSITY_POINTS_COLOR;
     global $GRAPH_DENSITY_POINTS_OUTLINE;
     global $JPGRAPH_VERSION;
     if ($this->ready) {
         return;
     }
     list($axes, $data, $spec) = $this->PrepareData($this->reader, $mask, $iv);
     $draw_modes = array();
     foreach ($data as $info) {
         $items = $info['items'];
         foreach ($items as $item) {
             array_push($draw_modes, $item['draw_mode']);
         }
     }
     $this->plot_mode = $this->FindPlotMode($this->req->props['plot_mode']);
     $this->AnalyzeGapsRequirements($axes, $data, $spec);
     $this->AnalyzeMarksRequirements($axes, $data, $spec);
     list($xaxis, $yaxis) = $this->ConfigureAxis($axes, $iv, $data, $spec);
     $this->spec =& $spec;
     $this->graph = new Graph($this->width, $this->height, "auto");
     $this->graph->SetTickDensity(TICKD_SPARSE, TICKD_SPARSE);
     if ($xaxis['date_format']) {
         $this->graph->SetScale("datlin", 0, 1, $xaxis['from'], $xaxis['to']);
         //$this->graph->xaxis->scale->Update($this->graph, $xaxis['from'], $xaxis['to']);
         $this->graph->xaxis->scale->SetDateFormat($xaxis['date_format']);
     } else {
         $this->graph->SetScale("linlin", 0, 1, $xaxis['from'], $xaxis['to']);
         if ($xaxis['ticks']) {
             $this->graph->xscale->ticks->Set($xaxis['ticks'][0], $xaxis['ticks'][1]);
         }
     }
     if ($xaxis['label_interval']) {
         $this->graph->xaxis->SetTextLabelInterval($xaxis['label_interval']);
     }
     if ($this->hide_axes) {
         if (strcasecmp($this->hide_axes, 'Y')) {
             $hide_x = true;
         } else {
             $hide_x = false;
         }
         $hide_y = true;
     } else {
         $hide_x = false;
         $hide_y = false;
     }
     $this->graph_margin = array();
     if ($hide_y) {
         $this->graph_yaxis_size = 0;
         if ($hide_x) {
             $this->graph_margin[0] = 0;
             $this->graph_margin[2] = 0;
         } else {
             $this->graph_margin[0] = $GRAPH_MARGINS['right'] + $GRAPH_MARGINS['axis'];
             $this->graph_margin[2] = $GRAPH_MARGINS['right'];
         }
         $this->graph->yaxis->HideLabels();
     } else {
         $this->graph_yaxis_size = $GRAPH_MARGINS['axis'];
         $this->graph_margin[0] = $GRAPH_MARGINS['left'] + $this->graph_yaxis_size * $axes->GetAxesNumber();
         $this->graph_margin[2] = $GRAPH_MARGINS['right'];
     }
     if ($hide_x) {
         $this->graph_margin[1] = 0;
         $this->graph_margin[3] = 1;
         $this->graph->xaxis->HideLabels();
     } else {
         $this->graph_margin[1] = $GRAPH_MARGINS['top'];
         $this->graph_margin[3] = $GRAPH_MARGINS['bottom'];
         $title = $this->GenerateTitle($data, $spec);
         $this->graph->title->Set($title);
         $this->graph->xaxis->SetPos("min");
         //$this->graph->xaxis->SetLabelAngle(0);
         $this->graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8);
         //$this->graph->xaxis->scale->SetTimeAlign(MINADJ_15);
         // We can use SetLabelFormatCallback for higher control
         //$this->graph->yaxis->SetLabelFormat('%0.5g');
         //$this->graph->SetYDeltaDist($this->graph_yaxis_size);
     }
     $this->graph->img->SetMargin($this->graph_margin[0], $this->graph_margin[2], $this->graph_margin[1], $this->graph_margin[3]);
     $this->graph->xaxis->SetLabelMargin(13);
     foreach ($axes as $axis_i => $axis) {
         $empty_axis = true;
         if (intval($this->plot_mode) === DRAW::PLOT_STANDARD) {
             foreach ($axis as $i => $plot_data) {
                 $plot = new LinePlot($plot_data[1], $plot_data[0]);
                 $color = $axis->GetChannelColor($i);
                 if ($color) {
                     $plot->SetColor($color);
                 }
                 $weight = $axis->GetChannelProperty($i, "weight");
                 if ($weight) {
                     $plot->SetWeight($weight);
                 }
                 if ($spec['marks']) {
                     $prop = $axis->GetChannelProperty($i, "mark_type");
                     if ($prop) {
                         $plot->mark->SetType($prop);
                     }
                     $prop = $axis->GetChannelProperty($i, "mark_size");
                     if ($prop) {
                         $plot->mark->SetSize($prop);
                     }
                     $prop = $axis->GetChannelProperty($i, "mark_fill");
                     if ($prop) {
                         $plot->mark->SetFillColor($prop);
                     }
                 }
                 $this->graph->AddY($axis_i, $plot);
                 $empty_axis = false;
             }
         } else {
             if (intval($this->plot_mode) === DRAW::PLOT_CUSTOM) {
                 foreach ($data as $info) {
                     $acc_lineplot_array = array();
                     $lineplot_array = array();
                     $items = $info['items'];
                     $time = $info['time'];
                     $values = $info['values'];
                     foreach ($axis as $i => $plot_data) {
                         $plot = new LinePlot($plot_data[1], $plot_data[0]);
                         $color = $axis->GetChannelColor($i);
                         if ($color) {
                             $plot->SetColor($color);
                         }
                         $weight = $axis->GetChannelProperty($i, "weight");
                         if ($weight) {
                             $plot->SetWeight($weight);
                         }
                         if ($spec['marks']) {
                             $prop = $axis->GetChannelProperty($i, "mark_type");
                             if ($prop) {
                                 $plot->mark->SetType($prop);
                             }
                             $prop = $axis->GetChannelProperty($i, "mark_size");
                             if ($prop) {
                                 $plot->mark->SetSize($prop);
                             }
                             $prop = $axis->GetChannelProperty($i, "mark_fill");
                             if ($prop) {
                                 $plot->mark->SetFillColor($prop);
                             }
                         }
                         if ($items[$i]['draw_mode'] !== "LINE") {
                             $plot->SetFillColor($color);
                             array_push($acc_lineplot_array, $plot);
                         } else {
                             array_push($lineplot_array, $plot);
                         }
                         $empty_axis = false;
                     }
                     if (!empty($acc_lineplot_array)) {
                         $accplot = new AccLinePlot($acc_lineplot_array);
                         $this->graph->AddY($axis_i, $accplot);
                     }
                     if (!empty($lineplot_array)) {
                         foreach ($lineplot_array as $plot) {
                             $this->graph->AddY($axis_i, $plot);
                         }
                     }
                 }
             }
         }
         if ($empty_axis) {
             $plot = new LinePlot(array(0), array($spec['from']));
             $this->graph->AddY($axis_i, $plot);
         }
         $range = $axis->GetRange();
         $scale = $axis->IsLogarithmic() ? "log" : "lin";
         if ($range) {
             if ($axis->IsLogarithmic()) {
                 if ($range[0] <= 0) {
                     $range[0] = DRAW::MIN_LOG;
                 }
                 if ($range[1] <= 0) {
                     $range[1] = 1;
                 }
                 $this->graph->SetYScale($axis_i, $scale, log10($range[0]), log10($range[1]));
                 //	        $this->graph->SetYScale($axis_i, $scale, (log10(max(DRAW::MIN_LOG, $range[0]))), (log10(max(DRAW::MIN_LOG, $range[1]))));
             } else {
                 $this->graph->SetYScale($axis_i, $scale, $range[0], $range[1]);
             }
         } else {
             if ($empty_axis) {
                 $this->graph->SetYScale($axis_i, $scale, 0, 1);
             } else {
                 $this->graph->SetYScale($axis_i, $scale);
             }
         }
         $color = $axis->GetColor();
         $this->graph->ynaxis[$axis_i]->SetColor($color);
         if ($hide_y) {
             $this->graph->ynaxis[$axis_i]->HideLabels();
         } else {
             $this->graph->ynaxis[$axis_i]->SetPos("min");
             $this->graph->ynaxis[$axis_i]->SetTickSide(SIDE_RIGHT);
             $this->graph->ynaxis[$axis_i]->SetLabelSide(SIDE_LEFT);
             $this->graph->ynaxis[$axis_i]->SetPosAbsDelta(-$axis_i * $this->graph_yaxis_size - 2);
             if (!$range) {
                 $this->graph->ynaxis[$axis_i]->scale->SetGrace(0.1, 0.1);
             }
             $title = $axis->GetTitle();
             if ($title) {
                 $this->graph->ynaxis[$axis_i]->SetTitle($title, "high");
                 $this->graph->ynaxis[$axis_i]->SetTitleSide(SIDE_LEFT);
                 if ($JPGRAPH_VERSION > 2) {
                     $this->graph->ynaxis[$axis_i]->SetTitleMargin(15 - $this->graph_yaxis_size);
                 } else {
                     $this->graph->ynaxis[$axis_i]->SetTitleMargin($this->graph_yaxis_size - 20);
                 }
                 $this->graph->ynaxis[$axis_i]->title->SetColor($color);
                 $this->graph->ynaxis[$axis_i]->HideLastTickLabel();
             }
         }
         // We can use SetLabelFormatCallback for higher control
         //$this->graph->ynaxis[$axis_i]->SetLabelFormat('%0.5g');
         $this->graph->ynaxis[$axis_i]->SetLabelFormatCallback(array(new DRAW_JPGraphAxisHolder($this, $axis, $this->graph->ynaxis[$axis_i]), "YLabelFormat"));
     }
     /*
         $plot = new LinePlot(array(0), array($spec['from']));
         $this->graph->AddY(1, $plot);
         $this->graph->SetYScale(1, 'lin', $range[0], $range[1]);
             $this->graph->ynaxis[1]->SetPos("min");
             $this->graph->ynaxis[1]->SetTitleSide(SIDE_LEFT);
             $this->graph->ynaxis[1]->SetTickSide(SIDE_RIGHT);
             $this->graph->ynaxis[1]->SetLabelSide(SIDE_LEFT);
     	$this->graph->ynaxis[1]->SetPosAbsDelta(-1 * 60 - 2);
     */
     $something_shown = false;
     if ($spec['gaps']) {
         //$px = ($max - $min) / $this->height; $realmax = $max + 2*$px;
         $realmax = 1 + 3 / $this->height;
         switch ($spec['gaps']) {
             case DRAW::SHOW_GAPS:
                 $gtime = array();
                 $gvalue = array();
                 foreach ($data as &$info) {
                     $flag = 0;
                     foreach ($info['gaps'] as $idx => &$val) {
                         if ($val) {
                             if ($flag) {
                                 $flag++;
                             } else {
                                 array_push($gtime, $info['time'][$idx]);
                                 array_push($gvalue, $realmax);
                                 $flag = 1;
                             }
                         } else {
                             if ($flag) {
                                 array_push($gtime, $info['time'][$idx]);
                                 array_push($gvalue, $realmax);
                                 array_push($gtime, $info['time'][$idx]);
                                 array_push($gvalue, false);
                                 $flag = 0;
                             }
                         }
                     }
                     if (sizeof($gtime) > 0) {
                         $something_shown = true;
                         $plot = new LinePlot($gvalue, $gtime);
                         $plot->SetColor($GRAPH_DENSITY_PLOT_INVALID_COLOR);
                         $plot->SetWeight($GRAPH_DENSITY_PLOT_INVALID_SIZE);
                         $this->graph->Add($plot);
                     }
                 }
                 break;
             case DRAW::SHOW_POINTS:
                 $something_shown = true;
                 foreach ($data as &$info) {
                     foreach ($info['gaps'] as $idx => &$val) {
                         if ($val > 1) {
                             $val = false;
                         } else {
                             $val = $realmax;
                         }
                     }
                     //		print_r($info['gaps']);
                     $plot = new LinePlot($info['gaps'], $info['time']);
                     $plot->SetColor($GRAPH_DENSITY_PLOT_VALID_COLOR);
                     $plot->SetWeight($GRAPH_DENSITY_PLOT_VALID_SIZE);
                     if ($GRAPH_DENSITY_POINTS_TYPE) {
                         eval("\$mtype={$GRAPH_DENSITY_POINTS_TYPE};");
                     }
                     $plot->mark->SetType($mtype);
                     $plot->mark->SetColor($GRAPH_DENSITY_POINTS_OUTLINE);
                     $plot->mark->SetFillColor($GRAPH_DENSITY_POINTS_COLOR);
                     $plot->mark->SetSize($GRAPH_DENSITY_POINTS_SIZE);
                     $this->graph->Add($plot);
                 }
         }
     }
     if (!$something_shown) {
         $plot = new LinePlot(array(0), array($spec['from']));
         $this->graph->Add($plot);
     }
     $this->graph->yaxis->Hide();
     $this->graph_interval = $iv;
     $this->graph_axes = $axes;
     $this->precision = $spec['precision'];
 }
Ejemplo n.º 24
0
    list($nxdata, $nydata) = $spline->get(100);
    $lineplot = new LinePlot($nydata, $nxdata);
} else {
    $lineplot = new LinePlot($ydata, $xdata);
}
//	echo '<pre>';
//	$i = 0;
//	foreach ($xdata as $date){
//		echo $i . ' | ' . $date . ' | ' . date('j-m-Y',$date) . ' | ' . $ydata[$i] . "\n";
//		$i++;
//	}
//
//
//	echo '</pre>';
$lineplot->SetColor('blue');
$lineplot->SetFillColor("blue@0.8");
if ($starttime > strtotime('-13 months', $endtime)) {
    $lineplot->SetStepStyle(true);
}
$orangeline = new PlotLine(HORIZONTAL, $aantalbedden * 0.8, 'orange', 1);
$redline = new PlotLine(HORIZONTAL, $aantalbedden * 0.9, 'red', 1);
$maxline = new PlotLine(HORIZONTAL, $aantalbedden, 'black', 1);
// Add the plot to the graph
$graph->Add($lineplot);
$graph->AddLine($orangeline);
$graph->AddLine($redline);
$graph->AddLine($maxline);
if ($starttime < strtotime('-6 months', $endtime)) {
    // Trend
    $prec = floor(count($ydata) / 10);
    //echo $prec . '<br />';
Ejemplo n.º 25
0
    foreach ($lines as $line => $datarow) {
        $split = preg_split('/[\\s]+/', $datarow);
        $aYears[] = substr(trim($split[0]), 0, 4);
        $aSunspots[] = trim($split[1]);
    }
}
$year = array();
$ydata = array();
readsunspotdata('yearssn.txt', $year, $ydata);
// Width and height of the graph
$width = 600;
$height = 200;
// Create a graph instance
$graph = new Graph($width, $height);
// Specify what scale we want to use,
// int = integer scale for the X-axis
// int = integer scale for the Y-axis
$graph->SetScale('intint');
// Setup a title for the graph
$graph->title->Set('Sunspot example');
// Setup titles and X-axis labels
$graph->xaxis->title->Set('(year from 1701)');
// Setup Y-axis title
$graph->yaxis->title->Set('(# sunspots)');
// Create the linear plot
$lineplot = new LinePlot($ydata);
$lineplot->SetFillColor('orange@0.5');
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
Ejemplo n.º 26
0
    }
}
if (!$found) {
    $name = 'no_data.png';
    $fp = fopen($name, 'rb');
    // send the right headers
    header("Content-Type: image/png");
    header("Content-Length: " . filesize($name));
    // dump the picture and stop the script
    fpassthru($fp);
    exit;
}
$sewer_plot = new LinePlot($sewer, $ts);
$sewer_plot->SetColor('darkgoldenrod');
$sewer_plot->SetWeight(2);
$sewer_plot->SetFillColor($line_fill_color);
$graph = new Graph($width, $height);
$graph->SetFrame(false);
if ($zoom_level == 0) {
    $graph->SetBackgroundImage('background_h_33_66.png', BGIMG_FILLPLOT);
} else {
    $graph->SetBackgroundImage('background_h_10_20.png', BGIMG_FILLPLOT);
}
$graph->SetBackgroundImageMix(35);
$graph->SetMargin(60, 60, 40, 50);
$graph->SetMarginColor('white');
$graph->SetScale('datlin', $SEWER_MIN, $SEWER_MAX[$zoom_level]);
$graph->Add($sewer_plot);
$graph->ygrid->SetColor("azure3");
$graph->xaxis->SetLabelAngle(90);
$graph->xaxis->scale->SetDateFormat('g a');
Ejemplo n.º 27
0
 public function bytes_s()
 {
     require_once 'jpgraph/jpgraph.php';
     require_once 'jpgraph/jpgraph_line.php';
     require_once 'jpgraph/jpgraph_date.php';
     $size = $this->uri->segment(3);
     $server_id = $this->uri->segment(4);
     $time = $this->uri->segment(5);
     $server = $this->server->get_record_by_id($server_id);
     $start = time() - $time;
     $mcount = $time / 60;
     $data = array();
     $xdata = array();
     for ($i = 0; $i < $mcount; ++$i) {
         $time = $start + $i * 60;
         $xdata[$i] = $time;
         $date_min = date('YmdHi', $time);
         $query = $this->db->query("select Bytes_sent from mysql_status_ext_history where server_id='{$server_id}' and YmdHi = '" . $date_min . "'; ");
         if ($query->num_rows() > 0) {
             $row = $query->row();
             $yresult = $row->Bytes_sent;
         } else {
             $yresult = '0';
         }
         $ydata[$i] = $yresult;
     }
     // Create the graph. These two calls are always required
     if ($size == 'small') {
         $width = 400;
         $height = 260;
     } else {
         if ($size = 'large') {
             $width = 1280;
             $height = 400;
         }
     }
     $graph = new Graph($width, $height);
     //$graph->SetScale("textlin");
     $graph->SetScale('datelin');
     $graph->xaxis->SetLabelAngle(90);
     $graph->xaxis->scale->SetDateFormat('H:i');
     $graph->SetShadow();
     $graph->img->SetMargin(40, 20, 20, 40);
     $dplot = new LinePlot($ydata, $xdata);
     $dplot->SetFillColor("orange@0.3");
     // Add the plot to the graph
     $graph->Add($dplot);
     $graph->xaxis->SetTextTickInterval(2);
     $grapha_title = $server['host'] . ":" . $server['port'] . " " . $server['application'] . " Sent Flow(KB)";
     $graph->title->Set($grapha_title);
     $graph->xaxis->title->Set("");
     $graph->yaxis->title->Set("");
     $graph->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
     $graph->Stroke();
 }
 /**
  *
  * @param Integer $groupId
  * @param String  $groupBy
  * @param Date    $startDate
  * @param Date    $endDate
  * @param Boolean $absolute Is y-axis relative to data set or absolute (starting from 0)
  */
 function displayProjectTotalSizeGraph($groupId, $groupBy, $startDate, $endDate, $absolute = true)
 {
     $graph = new Chart(420, 340, "auto");
     $graph->img->SetMargin(70, 50, 30, 70);
     $graph->SetScale("textlin");
     $graph->title->Set("Total project size growth over the time");
     $graph->yaxis->title->Set("Size");
     $graph->yaxis->SetTitleMargin(60);
     $graph->yaxis->setLabelFormatCallback(array($this, 'sizeReadable'));
     if ($absolute) {
         $graph->yaxis->scale->SetAutoMin(0);
     }
     $data = $this->_dum->getWeeklyEvolutionProjectTotalSize($groupId, $groupBy, $startDate, $endDate);
     if (is_array($data) && count($data) > 1) {
         $dates = array();
         $ydata = array();
         foreach ($data as $xdate => $values) {
             $dates[] = $xdate;
             $ydata[] = (double) $values;
         }
         $lineplot = new LinePlot($ydata);
         $color = '#6BA132';
         $lineplot->SetColor($color);
         $lineplot->SetFillColor($color . ':1.5');
         $lineplot->value->SetFont($graph->getFont(), FS_NORMAL, 8);
         $lineplot->value->setFormatCallback(array($this, 'sizeReadable'));
         $graph->Add($lineplot);
         $graph->xaxis->title->Set("Weeks");
         $graph->xaxis->SetTitleMargin(35);
         $graph->xaxis->SetTickLabels($dates);
         $graph->Stroke();
     } else {
         $this->displayError($GLOBALS['Language']->getText('plugin_statistics', 'no_data_error'));
     }
 }
Ejemplo n.º 29
0
require_once "jpgraph/jpgraph_line.php";
$l1datay = array(11, 9, 2, 4, 3, 13, 17);
$l2datay = array(23, 12, 5, 19, 17, 10, 15);
$datax = array('Jan', 'Feb', 'Mar', 'Apr', 'May');
// Create the graph.
$graph = new Graph(400, 200);
$graph->SetScale('textlin');
$graph->img->SetMargin(40, 130, 20, 40);
$graph->SetShadow();
// Create the linear error plot
$l1plot = new LinePlot($l1datay);
$l1plot->SetColor('red');
$l1plot->SetWeight(2);
$l1plot->SetLegend('Prediction');
// Create the bar plot
$l2plot = new LinePlot($l2datay);
$l2plot->SetFillColor('orange');
$l2plot->SetLegend('Result');
// Add the plots to the graph
$graph->Add($l2plot);
$graph->Add($l1plot);
$graph->title->Set('Mixing line and filled line');
$graph->xaxis->title->Set('X-title');
$graph->yaxis->title->Set('Y-title');
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
//$graph->xaxis->SetTickLabels($datax);
//$graph->xaxis->SetTextTickInterval(2);
// Display the graph
$graph->Stroke();
Ejemplo n.º 30
0
    $datay[] = rand(30, 150);
}
// Setup the basic graph
$graph = new Graph(324, 250);
$graph->SetMargin(40, 40, 30, 70);
$graph->title->Set('Date: ' . date('Y-m-d', $now));
$graph->SetAlphaBlending();
// Setup a manual x-scale (We leave the sentinels for the
// Y-axis at 0 which will then autoscale the Y-axis.)
// We could also use autoscaling for the x-axis but then it
// probably will start a little bit earlier than the first value
// to make the first value an even number as it sees the timestamp
// as an normal integer value.
$graph->SetScale("intlin", 0, 200, $now, $datax[$n - 1]);
// Setup the x-axis with a format callback to convert the timestamp
// to a user readable time
$graph->xaxis->SetLabelFormatCallback('TimeCallback');
$graph->xaxis->SetLabelAngle(90);
// Create the line
$p1 = new LinePlot($datay, $datax);
$p1->SetColor("blue");
// Set the fill color partly transparent
$p1->SetFillColor("blue@0.4");
// Add lineplot to the graph
$graph->Add($p1);
// Output line
$graph->Stroke();
?>