$graph->xaxis->SetTickSide(SIDE_DOWN); $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.
/** * Draw the XY type plot * * @param array $data plot data array reference * @param array $xmlArr xml array reference * @return object refernce XY plot object reference */ public function renderXYPlot(&$data, &$xmlArr) { $id = $xmlArr['ATTRIBUTES']['ID']; $field = $xmlArr['ATTRIBUTES']['FIELD']; $chartType = $xmlArr['ATTRIBUTES']['CHARTTYPE']; $pointType = $xmlArr['ATTRIBUTES']['POINTTYPE']; $weight = $xmlArr['ATTRIBUTES']['WEIGHT']; $color = $xmlArr['ATTRIBUTES']['COLOR']; $fillColor = $xmlArr['ATTRIBUTES']['FILLCOLOR']; $showVal = $xmlArr['ATTRIBUTES']['SHOWVALUE']; $legend = $xmlArr['ATTRIBUTES']['LEGENDFIELD']; $visible = $xmlArr['ATTRIBUTES']['VISIBLE']; if ($chartType == 'Line' or $chartType == 'Bar') { if ($chartType == 'Line') { include_once JPGRAPH_DIR . '/jpgraph_line.php'; $plot = new LinePlot($data); $this->_drawMark($plot->mark, $xmlArr['POINTMARK']['ATTRIBUTES']['TYPE'], $xmlArr['POINTMARK']['ATTRIBUTES']['COLOR'], $xmlArr['POINTMARK']['ATTRIBUTES']['FILLCOLOR'], $xmlArr['POINTMARK']['ATTRIBUTES']['SIZE']); $plot->SetBarCenter(); $plot->SetCenter(); } else { if ($chartType == 'Bar') { include_once JPGRAPH_DIR . '/jpgraph_bar.php'; $plot = new BarPlot($data); $plot->SetAlign('center'); } } if ($color) { $plot->SetColor($color); } if ($fillColor) { $plot->SetFillColor($fillColor); } if ($weight) { $plot->SetWeight($weight); } if ($showVal == 1) { $plot->value->Show(); } if ($legend) { $plot->SetLegend($legend); } $this->_drawString($plot->value, $xmlArr['VALUE']['ATTRIBUTES']['FONT'], $xmlArr['VALUE']['ATTRIBUTES']['COLOR']); } if ($chartType == 'GroupBar' or $chartType == 'AccBar') { $children = $xmlArr['ATTRIBUTES']['CHILDREN']; $childList = explode(",", $children); foreach ($childList as $child) { $childPlotList[] = $this->m_PlotList[$child]; } if ($chartType == 'GroupBar') { $plot = new GroupBarPlot($childPlotList); } else { if ($chartType == 'AccBar') { $plot = new AccBarPlot($childPlotList); } } } $this->m_PlotList[$id] = $plot; if ($visible == 1) { return $plot; } return null; }
function graficar_defectos($eje_y, $x_label, $pareto, $titulo_eje_x, $titulo_eje_y, $title, $name) { include "../jpgraph/src/jpgraph.php"; include "../jpgraph/src/jpgraph_line.php"; include "../jpgraph/src/jpgraph_bar.php"; $graph = new Graph(820, 350); $graph->SetScale("textlin"); $graph->SetMarginColor("#FFFFFF"); $graph->img->SetMargin(80, 80, 60, 140); $graph->yaxis->SetTitleMargin(40); $graph->SetBackgroundImage("../imagenes/fondo.jpg", BGIMG_FILLFRAME); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetTickLabels($x_label); $graph->legend->Pos(0.03, 0.3); $graph->title->SetColor("#000000"); $graph->title->Set($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->yaxis->title->Set($titulo_eje_y); //$graph->xaxis->title->Set($titulo_eje_x); $graph->setcolor("#EEEEEE"); $graph->setshadow("true", 3, "#aaaaaa"); // Crear la gráfica de barras $bplot1 = new BarPlot($eje_y); $bplot1->SetWidth(0.3); $bplot1->SetYMin(0.02); $bplot1->SetFillColor("orange@0.2"); $bplot1->SetShadow('darkgray'); $bplot1->value->SetFormat("%0.1f"); $bplot1->value->SetColor("darkred"); $bplot1->value->Show(); // Crear la gráfica de líneas $lplot = new LinePlot($pareto); $lplot->mark->SetType(MARK_FILLEDCIRCLE); $lplot->mark->SetFillColor("red"); $lplot->mark->SetWidth(3); $lplot->SetColor("blue"); $lplot->SetBarCenter(); $graph->Add($bplot1); $graph->Add($lplot); $graph->Stroke("charts/" . $name); }
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); }
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_bar.php'; require_once 'jpgraph/jpgraph_line.php'; $ydata = array(12, 15, 22, 19, 5); $graph = new Graph(400, 200); $graph->img->SetMargin(40, 80, 40, 40); $graph->SetScale("textlin"); $graph->SetShadow(); $graph->title->Set('Center the line points in bars'); $line = new LinePlot($ydata); $line->SetBarCenter(); $line->SetWeight(2); $bar = new BarPlot($ydata); $bar2 = new BarPlot($ydata); $bar2->SetFillColor("red"); $gbar = new GroupbarPlot(array($bar, $bar2)); $graph->Add($gbar); $graph->Add($line); // Output line $graph->Stroke(); ?>
$l1datay = array(11, 9, 2, 4, 3, 13, 17); $l2datay = array(23, 12, 5, 19, 17, 10, 15); $datax = $gDateLocale->GetShortMonth(); // Create the graph. $graph = new Graph(400, 200, "auto"); $graph->SetScale("textlin"); $graph->SetMargin(40, 130, 20, 40); $graph->SetShadow(); $graph->xaxis->SetTickLabels($datax); // Create the linear error plot $l1plot = new LinePlot($l1datay); $l1plot->SetColor("red"); $l1plot->SetWeight(2); $l1plot->SetLegend("Prediction"); //Center the line plot in the center of the bars $l1plot->SetBarCenter(); // Create the bar plot $bplot = new BarPlot($l2datay); $bplot->SetFillColor("orange"); $bplot->SetLegend("Result"); // Add the plots to t'he graph $graph->Add($bplot); $graph->Add($l1plot); $graph->title->Set("Adding a line plot to a bar graph v1"); $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); // Display the graph $graph->Stroke();
/** * Un tableau contenant les moyennes des eleves pour chaque sequences * * @param type $moyennes = array() */ function genererCourbe($moyennes, $rang, $codeperiode = "S") { try { # Donnees de la courbe $ydata = $moyennes; $ydata2 = $moyennes; /* for ($i = 1; $i <= 6; $i++) { $r = rand(0, 20); $ydata[] = $r; $ydata2[] = $r; } */ /** Definition des label de l'axe x */ if ($codeperiode === "T") { $datax = array("TRIM1", "TRIM2", "TRIM3"); } else { $datax = array("seq 1", "seq 2", "seq 3", "seq 4", "seq 5", "seq 6"); } # Creation du graph $graph = new Graph(350, 250, 'auto'); $graph->SetMarginColor('white'); # Definir le max et le min des valeur X $graph->SetScale('textlin', 0, 20); #$graph->xaxis->title->Set("Séquences"); $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD, 12); $graph->yaxis->title->Set("Moyennes"); $graph->xaxis->SetTickLabels($datax); $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 12); if ($codeperiode === "T") { $graph->xaxis->SetTitle("Trimestres", "middle"); } else { $graph->xaxis->SetTitle("Séquences", "middle"); } $graph->SetBackgroundGradient('white', 'lightblue', GRAD_HOR, BGRAD_PLOT); # Adjuster les margins (left, right, top, bottom) $graph->SetMargin(40, 5, 21, 45); # Box autour du plotarea $graph->SetBox(); # Un cadre ou frame autour de l'image $graph->SetFrame(false); # Definir le titre tabulaire $graph->tabtitle->SetFont(FF_ARIAL, FS_BOLD, 8); $graph->tabtitle->Set($_SESSION['anneeacademique']); # Definir le titre du graphe $graph->title->SetFont(FF_VERDANA, FS_BOLD, 8); $graph->title->SetAlign("right"); if (count($ydata) > 1) { $prev = $ydata[count($ydata) - 2]; if ($prev < $ydata[count($ydata) - 1]) { $graph->title->Set("Performance en hausse"); } elseif ($prev == $ydata[count($ydata) - 1]) { $graph->title->Set("Performance constante"); } else { $graph->title->Set("Performance en baisse"); } } # Definir les grid X et Y $graph->ygrid->SetFill(true, '#BBBBBB@0.9', '#FFFFFF@0.9'); //$graph->ygrid->SetLineStyle('dashed'); //$graph->ygrid->SetColor('gray'); //$graph->xgrid->SetLineStyle('dashed'); $graph->xgrid->SetColor('gray'); $graph->xgrid->Show(); //$graph->ygrid->Show(); #$graph->SetBackgroundGradient('blue','navy:0.5',GRAD_HOR,BGRAD_MARGIN); $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 8); $graph->xaxis->SetLabelAngle(0); # Creation d'une bar pot $bplot = new BarPlot($ydata); $bplot->SetWidth(0.9); $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); # Create filled line plot $lplot = new LinePlot($ydata2); $lplot->SetFillColor('skyblue@0.5'); $lplot->SetStyle(1); $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(5); # Afficher les moyenne au dessus des barres $accbarplot = new AccBarPlot(array($bplot)); $accbarplot->value->SetFormat("%.2f"); $accbarplot->value->Show(); $graph->Add($accbarplot); $graph->SetBackgroundImageMix(50); # Definir un fond d'ecran pour l'image $background = SITE_ROOT . "public/photos/eleves/" . $rang['PHOTOEL']; if (!empty($rang['PHOTOEL']) && file_exists(ROOT . DS . "public" . DS . "photos" . DS . "eleves" . DS . $rang['PHOTOEL'])) { $graph->SetBackgroundImage($background, BGIMG_FILLPLOT); # $icon = new IconPlot($background, 25, 25, 0.8, 50); } else { //$graph->SetBackgroundImage(SITE_ROOT . "public/img/". LOGO, BGIMG_FILLPLOT); # $icon = new IconPlot(SITE_ROOT . "public/img/ipw.png", 25, 25, 0.8, 50); } # $icon->SetAnchor('right', 'bottom'); $graph->Add($lplot); // Display the graph $filename = ROOT . DS . "public" . DS . "tmp" . DS . $rang['IDELEVE'] . ".png"; if (file_exists($filename)) { unlink($filename); } $graph->Stroke($filename); //echo "<img src='" . SITE_ROOT . "public/tmp/emp.png' />"; } catch (Exception $e) { var_dump($e); } }
constant(imgdef($q['frame']['style'], 'BGRAD_MARGIN')) ); /**/ //$graph->SetFrame(false); $graph->SetMarginColor(imgdef($q['frame']['margin'], '#d7d7d7')); $graph->SetFrame(true, imgdef($q['frame']['color'], 'gray'), imgdef($q['frame']['width'], 1)); //$graph->SetShadow(); //$smooth = max(imgdef($q['smooth'], 10), 10); $s = new Spline($datax, $datay); list($x, $y) = $s->Get(count($datay) * $smooth); // Create the bar pot $p1 = new LinePlot($y); $p1->SetLegend(imgdef($q['frame']['plot'][0]['_content'], 'Maximum') . " [{$maxconn}]"); $p1->SetWeight(imgdef($q['frame']['plot'][0]['weight'], 1)); $p1->SetFillColor(imgdef($q['frame']['plot'][0]['color'], 'blue@0.90')); $p1->SetBarCenter(); $avg = intval($avg); if ($avg) { $avgdata = array(); for ($i = 0; $i < count($datay) * $smooth; $i++) { $avgdata[] = $avg; } $p2 = new LinePlot($avgdata); // $p2->SetStyle('dashed'); $p2->SetLegend(imgdef($q['frame']['plot'][1]['_content'], 'Average') . " [{$avg}]"); $p2->SetWeight(imgdef($q['frame']['plot'][1]['weight'], 2)); $p2->SetColor(imgdef($q['frame']['plot'][1]['color'], 'khaki4')); $p2->SetBarCenter(); $graph->Add($p2); $graph->legend->SetAbsPos(imgdef($q['legend']['x'], 20), imgdef($q['legend']['y'], 15), imgdef($q['legend']['halign'], 'right'), imgdef($q['legend']['valign'], 'top')); $graph->legend->SetFillColor(imgdef($q['legend']['color'], 'lightblue@0.5'));
/** * Execute the action * * @return mixed * @access public * @since 2/28/08 */ public function execute() { // New graph with a drop shadow $graph = new Graph(800, 600, 'auto'); $graph->SetShadow(); // Use a "text" X-scale $graph->SetScale("textlin"); // Specify X-labels //$databarx = array('tXi','','','xxx','','','iXii','','','OOO','','','tOO'); $graph->xaxis->SetFont(FF_VERA, FS_NORMAL); $graph->xaxis->SetTickLabels($this->getLabels()); $graph->xaxis->SetLabelAngle(45); $days = $this->getNumDays(); // Between 3 and 20 weeks, use weekly intervals if ($days > 21 && $days < 140) { $graph->xaxis->SetTextLabelInterval(7); } else { if ($days >= 140) { $graph->xaxis->SetTextLabelInterval(round($days / 20)); } } $graph->SetMargin(40, 20, 40, 80); // Set title and subtitle $title = _("Segue Usage for the past %1 %2"); $title = str_replace('%1', $this->getIntervalSize(), $title); if ($this->getIntervalSize() == 1) { $unit = $this->getIntervalUnit(); } else { $unit = $this->getIntervalUnit() . 's'; } $title = str_replace('%2', ucfirst(strtolower($unit)), $title); $graph->title->Set($title); // Use built in font $graph->title->SetFont(FF_VERA, FS_BOLD); $graph->legend->SetFont(FF_VERA, FS_NORMAL); // Create the bar plot $b1 = new BarPlot($this->getEdits()); $b1->SetLegend(_("Edits")); $b1->SetFillColor('#7778F3'); $b2 = new BarPlot($this->getFiles()); $b2->SetLegend(_("Files")); $b2->SetFillColor('#FFCB3F'); $b3 = new BarPlot($this->getComments()); $b3->SetLegend(_("Discussion Posts")); $b3->SetFillColor('#89DF6D'); $accbar = new AccBarPlot(array($b1, $b2, $b3)); $accbar->SetWidth(1); //$b1->SetShadow(); $graph->Add($accbar); $line = new LinePlot($this->getErrors()); $line->SetLegend(_("Errors")); $line->SetColor('#FF0000'); $line->SetWeight(1); $line->SetBarCenter(true); $graph->Add($line); $line = new LinePlot($this->getLogins()); $line->SetLegend(_("Logins")); $line->SetColor('#615FFF'); $line->SetWeight(1); $line->SetBarCenter(true); $graph->Add($line); $line = new LinePlot($this->getUsers()); $line->SetLegend(_("Distinct Users")); $line->SetColor('#0300FF'); $line->SetWeight(3); $line->SetBarCenter(true); // For months and less, display value for the number of users if ($days < 32) { $line->value->Show(); $line->value->HideZero(); $line->value->SetFormat("%d"); } $graph->Add($line); // Finally output the image $graph->Stroke(); exit; }