public static function lineChart($data1, $data2, $legends) { $graph = new Graph(600, 400); $graph->SetScale('intlin'); $graph->SetShadow(); $graph->SetMargin(40, 20, 20, 40); // $graph->title->Set('Calls per operator (June,July)'); // $graph->subtitle->Set('(March 12, 2008)'); // $graph->xaxis->title->Set('Operator'); // $graph->yaxis->title->Set('# of calls'); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetTickLabels($legends); $lineplot = new LinePlot($data1); $lineplot->SetWeight(4); // Two pixel wide // Add the plot to the graph $graph->Add($lineplot); // Create the second data series $lineplot2 = new LinePlot($data2); $lineplot2->SetWeight(4); // Two pixel wide $graph->Add($lineplot2); $lineplot->SetLegend("This Year"); $lineplot2->SetLegend("Last Year"); $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->Pos(0.4, 0.95, "center", "bottom"); return $graph->Stroke('../graph/compareLineChart.png'); }
public function graficofecha($gestion) { if (Conectar::con()) { //$gestion='2013'; $objetoanalisis = new classAnalisis(); $anio = $gestion; for ($i = 0; $i < 12; $i++) { $dat[] = $objetoanalisis->ventamensual($anio, $i); } $datos = $dat; //$datos =array('1','4','3','3','5'); $grafico = new Graph(400, 300, "auto"); $grafico->SetScale("textlin"); $grafico->title->Set("Resumen de ventas por gestion"); $grafico->xaxis->title->Set(""); $grafico->yaxis->title->Set(""); // Un gradiente Horizontal de rojo a azul // 25 pixeles de ancho para cada barra $lineplot = new LinePlot($datos); $lineplot->SetColor("green"); $lineplot->SetWeight(2); $grafico->Add($lineplot); return $grafico->Stroke(); } }
function LineGraph($w, $h, $title, $data1, $data2, $datax, $output) { // Create the graph. These two calls are always required $graph = new Graph($w, $h, "auto"); $graph->SetScale("textlin"); $graph->SetMarginColor('white'); $graph->SetFrame(true); // Adjust the margin $graph->img->SetMargin(40, 100, 20, 40); $graph->SetShadow(false); // Create the linear plot $lineplot = new LinePlot($data1); $lineplot->SetWeight(2); $lineplot->SetColor("blue"); $lineplot->mark->SetType(MARK_DIAMOND); $lineplot->mark->SetWidth(5); $lineplot->mark->SetFillColor('blue'); $lineplot->value->SetMargin(-20); $lineplot->value->show(); $lineplot->value->SetColor('blue'); $lineplot->value->SetFormat('%0.0f'); $lineplot->SetLegend($_SESSION[Tahun1]); $lineplot2 = new LinePlot($data2); $lineplot2->SetColor("green"); $lineplot2->SetWeight(2); $lineplot2->mark->SetType(MARK_FILLEDCIRCLE); $lineplot2->mark->SetWidth(3); $lineplot2->mark->SetFillColor('green'); $lineplot2->value->show(); $lineplot2->value->SetColor('darkgreen'); $lineplot2->value->SetFormat('%0.0f'); $lineplot2->SetLegend($_SESSION[Tahun2]); // Add the plot to the graph $graph->Add($lineplot); $graph->xaxis->SetTickLabels($datax); $graph->title->Set($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->Add($lineplot2); $graph->legend->SetShadow(false); $graph->legend->SetFillColor('white'); $graph->legend->SetPos(0.01, 0.88, 'right', 'center'); // Display the graph $graph->Stroke($output); }
/** * @return Chart */ public function buildGraph() { $graph = new Chart($this->width, $this->height); $graph->SetScale("datlin"); $graph->title->Set($this->title); $graph->subtitle->Set($this->description); $colors = $graph->getThemedColors(); $graph->xaxis->SetTickLabels($this->burndown_data->getHumanReadableDates()); $remaining_effort = new LinePlot($this->burndown_data->getRemainingEffort()); $remaining_effort->SetColor($colors[1] . ':0.7'); $remaining_effort->SetWeight(2); $remaining_effort->SetLegend('Remaining effort'); $remaining_effort->mark->SetType(MARK_FILLEDCIRCLE); $remaining_effort->mark->SetColor($colors[1] . ':0.7'); $remaining_effort->mark->SetFillColor($colors[1]); $remaining_effort->mark->SetSize(3); $graph->Add($remaining_effort); $ideal_burndown = new LinePlot($this->burndown_data->getIdealEffort()); $ideal_burndown->SetColor($colors[0] . ':1.25'); $ideal_burndown->SetLegend('Ideal Burndown'); $graph->Add($ideal_burndown); return $graph; }
} // Create the graph. These two calls are always required $graph = new Graph($xsize, $ysize, "auto", 30); $graph->SetScale("textlin"); $graph->SetMarginColor("{$margincolour}"); $graph->yaxis->scale->SetGrace(10); $graph->SetShadow(); $graph->SetMargin($lm, $rm, $tm, $bm); // Create a line plot $lplot = new LinePlot($datay); $lplot2 = new LinePlot($datay2); // Adjust colours $lplot->SetColor("{$temp_col_max}"); $lplot->SetWeight(2); $lplot2->SetColor("{$temp_col_min}"); $lplot2->SetWeight(2); //Add plots $graph->Add($lplot); $graph->Add($lplot2); // Setup the titles $graph->title->Set("{$txt_temp} {$txt_31d} ({$temp_unit})"); $graph->title->SetColor("{$textcolour}"); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 10); //x-axis $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 8); $graph->xaxis->title->Set("{$txt_date}"); $graph->xaxis->title->SetColor("{$xtextcolour}"); $graph->xaxis->SetTickLabels($a); $graph->xaxis->SetTextLabelInterval(2); $graph->xaxis->SetPos("min"); $graph->xaxis->SetColor("{$xtextcolour}");
$graph = new Graph(500, 300); $graph->SetScale("loglog"); $graph->SetY2Scale("lin"); $graph->y2axis->SetColor("blue", "blue"); $graph->img->SetMargin(50, 70, 40, 50); $graph->title->Set("Geoelektrik"); $graph->xaxis->title->Set("Auslage ab/2 [m]"); $graph->yaxis->title->Set("rho_s [Ohm m]"); $graph->y2axis->title->Set("mn/2 [m]"); $graph->y2axis->title->SetColor("blue"); $graph->y2axis->SetTitleMargin(35); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xgrid->Show(true, true); $graph->ygrid->Show(true, true); // Create the linear plot $lineplot = new LinePlot($rhos, $ab2); $lineplot->SetWeight(1); $lineplot->mark->SetType(MARK_FILLEDCIRCLE); $lineplot->mark->SetWidth(2); // Create scatter plot $scplot = new ScatterPlot($mn2, $ab2); $scplot->mark->SetType(MARK_FILLEDCIRCLE); $scplot->mark->SetColor("blue"); $scplot->mark->SetWidth(2); // Add plots to the graph $graph->AddY2($scplot); $graph->Add($lineplot); // Display the graph $graph->Stroke();
<?php include "../jpgraph.php"; include "../jpgraph_line.php"; $ydata = array(12, 17, 22, 19, 5, 15); $graph = new Graph(270, 170); $graph->SetMargin(30, 90, 30, 30); $graph->SetScale("textlin"); $graph->img->SetAngle(90); $graph->img->SetCenter(floor(270 / 2), floor(170 / 2)); $line = new LinePlot($ydata); $line->SetLegend('2002'); $line->SetColor('darkred'); $line->SetWeight(2); $graph->Add($line); // Output graph $graph->Stroke(); ?>
$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); if ($_GET['95th']) {
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']; }
$graph->title->Set('Example of Function plot'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->subtitle->Set("(With some more advanced axis formatting\nHiding first and last label)"); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); $graph->xgrid->Show(); $graph->yaxis->SetPos(0); $graph->yaxis->SetWeight(2); $graph->yaxis->HideZeroLabel(); $graph->yaxis->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->SetColor('black', 'darkblue'); $graph->yaxis->HideTicks(true, false); $graph->yaxis->HideFirstLastLabel(); $graph->xaxis->SetWeight(2); $graph->xaxis->HideZeroLabel(); $graph->xaxis->HideFirstLastLabel(); $graph->xaxis->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetColor('black', 'darkblue'); $lp1 = new LinePlot($ydata, $xdata); $lp1->SetColor('blue'); $lp1->SetWeight(2); $lp2 = new LinePlot($y2data, $x2data); list($xm, $ym) = $lp2->Max(); $lp2->SetColor('red'); $lp2->SetWeight(2); $graph->Add($lp1); $graph->Add($lp2); $graph->Stroke(); ?>
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; }
public function curve_chart($total, $previousyear, $previousmonth, $xdata, $title) { require_once 'Examples/jpgraph/jpgraph.php'; require_once 'Examples/jpgraph/jpgraph_line.php'; require_once 'Examples/jpgraph/jpgraph_bar.php'; $datax = array('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'); // Create the graph. $graph = new Graph(1000, 400); $graph->SetScale("textlin"); $graph->SetMarginColor('white'); $graph->title->SetFont(FF_SIMSUN, FS_BOLD); // 设置中文字体 $graph->subtitle->SetFont(FF_SIMSUN); $graph->subsubtitle->SetFont(FF_SIMSUN); // Adjust the margin slightly so that we use the // entire area (since we don't use a frame) $graph->SetMargin(20, 1, 20, 90); // Box around plotarea $graph->SetBox(); // No frame around the image $graph->SetFrame(false); // Setup the tab title $graph->tabtitle->Set($title); $graph->tabtitle->SetFont(FF_SIMSUN, FS_BOLD, 10); // Setup the X and Y grid $graph->ygrid->SetFill(true, '#DDDDDD@0.5', '#BBBBBB@0.5'); $graph->ygrid->SetLineStyle('dashed'); $graph->ygrid->SetColor('gray'); $graph->xgrid->Show(); $graph->xgrid->SetLineStyle('dashed'); $graph->xgrid->SetColor('gray'); $graph->xaxis->SetLabelAngle(35); $graph->legend->SetFont(FF_SIMSUN, FS_NORMAL); $graph->legend->SetPos(0.01, 0.01); // Setup month as labels on the X-axis $graph->xaxis->SetTickLabels($xdata); $graph->xaxis->SetFont(FF_SIMSUN, FS_NORMAL, 8); // Create the linear error plot $l1plot = new LinePlot($previousyear); $l1plot->SetColor('red'); $l1plot->SetWeight(2); $l1plot->SetLegend('环比'); // Create the linear error plot $l2plot = new LinePlot($previousmonth); $l2plot->SetColor('yellow'); $l2plot->SetWeight(2); $l2plot->SetLegend('同比'); // Create the bar plot $bplot = new LinePlot($total); $bplot->SetColor('orange'); $bplot->SetWeight(2); $bplot->SetLegend('总量'); // Add the plots to t'he graph $graph->Add($bplot); $graph->Add($l1plot); $graph->Add($l2plot); // $graph->title->Set('Adding a line plot to a bar graph v1'); // $graph->xaxis->title->Set('X-title'); $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->xaxis->SetTickLabels($datax); //$graph->xaxis->SetTextTickInterval(2); // Display the graph $graph->Stroke(); }
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}"; }
$b1plot = new BarPlot($cdiff); $b1plot->SetFillColor("red"); $b1plot->SetLegend("Accum Difference"); $b2plot = new BarPlot($obs); $b2plot->SetFillColor("blue"); $b2plot->SetLegend("Obs Rain"); $g = new GroupBarPlot(array($b1plot, $b2plot)); $g->SetAlign("left"); } // Create the linear plot $lp1 = new LinePlot($aobs); $lp1->SetLegend("Actual Accum"); $lp1->SetColor("blue"); $lp1->SetWeight(2); if ($hasclimate && sizeof($cdiff) > 0) { $lp2 = new LinePlot($aclimate); $lp2->SetLegend("Climate Accum"); $lp2->SetColor("red"); $lp2->SetWeight(2); $z = new LinePlot($zeros); $z->SetWeight(2); } // Add the plot to the graph $graph->Add($lp1); if ($hasclimate && sizeof($cdiff) > 0) { $graph->Add($lp2); $graph->Add($g); $graph->Add($z); } // Display the graph $graph->Stroke();
$barplot_in->SetFillColor('#' . $config['graph_colours']['greens'][0]); $barplot_in->SetWeight(1); $barplot_out = new BarPlot($out_data); $barplot_out->SetLegend("Traffic Out"); $barplot_out->SetColor('#' . $config['graph_colours']['blues'][0]); $barplot_out->SetFillColor('#' . $config['graph_colours']['blues'][1]); $barplot_out->SetWeight(1); if ($imgtype == "historical") { $barplot_over = new BarPlot($overuse_data); $barplot_over->SetLegend("Traffic Overusage"); $barplot_over->SetColor('darkred'); $barplot_over->SetFillColor('lightred@0.4'); $barplot_over->SetWeight(1); $lineplot_allow = new LinePlot($allow_data); $lineplot_allow->SetLegend("Traffic Allowed"); $lineplot_allow->SetColor('black'); $lineplot_allow->SetWeight(1); $gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out, $barplot_over)); } else { $lineplot_allow = new LinePlot($ave_data); //$lineplot_allow->SetLegend("Average per ".$imgtype); $lineplot_allow->SetLegend("Average"); $lineplot_allow->SetColor('black'); $lineplot_allow->SetWeight(1); $gbplot = new GroupBarPlot(array($barplot_in, $barplot_tot, $barplot_out)); } $graph->Add($gbplot); $graph->Add($lineplot_allow); // Display the graph $graph->Stroke(); // EOF
if ($i % 10 == 0) { $databarx[] = $i; $databary[] = $datay[$i] / 2; } } // New graph with a background image and drop shadow $graph = new Graph(450, 300); $graph->img->SetMargin(40, 180, 40, 40); $graph->SetBackgroundImage("tiger_bkg.png", BGIMG_FILLFRAME); //$graph->img->SetAntiAliasing(); $graph->SetScale("intlin"); $graph->SetShadow(); $graph->title->Set("Combined bar and line plot"); $graph->subtitle->Set("(\"center\" aligned bars)"); // Use built in font $graph->title->SetFont(FF_FONT1, FS_BOLD); // Slightly adjust the legend from it's default position in the // top right corner. $graph->legend->Pos(0.05, 0.5, "right", "center"); // Create the first line $p1 = new LinePlot($datay, $datax); $p1->SetWeight(1); $p1->SetColor("red"); $p1->SetLegend("Triumph Tiger -98"); $graph->Add($p1); $b1 = new BarPlot($databary, $databarx); $b1->SetAbsWidth(10); $b1->SetAlign("center"); $b1->SetShadow(); $graph->Add($b1); $graph->Stroke();
/** * 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); } }
$ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7); $y2data = array(354, 200, 265, 99, 111, 91, 198, 225, 293, 251); // Create the graph and specify the scale for both Y-axis $graph = new Graph(300, 240, "auto"); $graph->SetScale("textlin"); $graph->SetShadow(); // Adjust the margin $graph->img->SetMargin(40, 40, 20, 70); // Create the two linear plot $lineplot = new LinePlot($ydata); $lineplot->SetStepStyle(); // Adjust the axis color $graph->yaxis->SetColor("blue"); $graph->title->Set("Example 6.2"); $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); // Set the colors for the plots $lineplot->SetColor("blue"); $lineplot->SetWeight(2); // Set the legends for the plots $lineplot->SetLegend("Plot 1"); // Add the plot to the graph $graph->Add($lineplot); // Adjust the legend position $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->Pos(0.4, 0.95, "center", "bottom"); // Display the graph $graph->Stroke();
function print_graph($g, $pgwidth) { $splines = false; $bandw = false; $percent = false; $show_percent = false; $stacked = false; $h = false; $show_values = false; $hide_grid = false; $hide_y_axis = false; if (isset($g['attr']['TYPE']) && $g['attr']['TYPE']) { $type = strtolower($g['attr']['TYPE']); } if (!in_array($type, array('bar', 'horiz_bar', 'line', 'radar', 'pie', 'pie3d', 'xy', 'scatter'))) { $type = 'bar'; } // Default=bar if (isset($g['attr']['STACKED']) && $g['attr']['STACKED']) { $stacked = true; } // stacked for bar or horiz_bar if (isset($g['attr']['SPLINES']) && $g['attr']['SPLINES'] && $type == 'xy') { $splines = true; } // splines for XY line graphs if (isset($g['attr']['BANDW']) && $g['attr']['BANDW']) { $bandw = true; } // black and white if (isset($g['attr']['LEGEND-OVERLAP']) && $g['attr']['LEGEND-OVERLAP']) { $overlap = true; } // avoid overlap of Legends over graph (line, bar, horiz_bar only) if (isset($g['attr']['PERCENT']) && $g['attr']['PERCENT'] && $type != 'xy' && $type != 'scatter') { $percent = true; } // Show data series as percent of total in series if (isset($g['attr']['SHOW-VALUES']) && $g['attr']['SHOW-VALUES']) { $show_values = true; } // Show the individual data values if (isset($g['attr']['HIDE-GRID']) && $g['attr']['HIDE-GRID']) { $hide_grid = true; } // Hide the y-axis gridlines if (isset($g['attr']['HIDE-Y-AXIS']) && $g['attr']['HIDE-Y-AXIS']) { $hide_y_axis = true; } // Hide the y-axis // Antialias: If true - better quality curves, but graph line will only be 1px even in PDF 300dpi // default=true for most except line and radar if (isset($g['attr']['ANTIALIAS']) && ($g['attr']['ANTIALIAS'] == '' || $g['attr']['ANTIALIAS'] == 0)) { $antialias = false; } else { if (isset($g['attr']['ANTIALIAS']) && $g['attr']['ANTIALIAS'] > 0) { $antialias = true; } else { if ($type == 'line' || $type == 'radar') { $antialias = false; } else { $antialias = true; } } } if ($g['attr']['DPI']) { $dpi = intval($g['attr']['DPI']); } if (!$dpi || $dpi < 50 || $dpi > 2400) { $dpi = 150; } // Default dpi 150 $k = 0.2645 / 25.4 * $dpi; // mPDF 4.5.009 global $JpgUseSVGFormat; if (isset($JpgUseSVGFormat) && $JpgUseSVGFormat) { $img_type = 'svg'; $k = 1; // Overrides as Vector scale does not need DPI } else { $img_type = 'png'; } if (isset($g['attr']['TITLE']) && $g['attr']['TITLE']) { $title = $g['attr']['TITLE']; } if (isset($g['attr']['LABEL-X']) && $g['attr']['LABEL-X']) { $xlabel = $g['attr']['LABEL-X']; } // NOT IMPLEMENTED?????? if (isset($g['attr']['LABEL-Y']) && $g['attr']['LABEL-Y']) { $ylabel = $g['attr']['LABEL-Y']; } if (isset($g['attr']['AXIS-X']) && $g['attr']['AXIS-X']) { $xaxis = strtolower($g['attr']['AXIS-X']); } if (!in_array($xaxis, array('text', 'lin', 'linear', 'log'))) { $xaxis = 'text'; } // Default=text if ($xaxis == 'linear') { $xaxis = 'lin'; } if (isset($g['attr']['AXIS-Y']) && $g['attr']['AXIS-Y']) { $yaxis = strtolower($g['attr']['AXIS-Y']); } if (!in_array($yaxis, array('lin', 'linear', 'log', 'percent'))) { $yaxis = 'lin'; } // Default=lin if ($yaxis == 'percent') { $show_percent = true; $yaxis = 'lin'; } // Show percent sign on scales if ($yaxis == 'linear') { $yaxis = 'lin'; } if ($splines) { $xaxis = 'lin'; } $axes = $xaxis . $yaxis; // e.g.textlin, textlog, loglog, loglin, linlog (XY) // mPDF 4.0 if (isset($g['attr']['cWIDTH']) && $g['attr']['cWIDTH']) { $w = $g['attr']['cWIDTH'] / 0.2645; } // pixels if (isset($g['attr']['cHEIGHT']) && $g['attr']['cHEIGHT']) { $h = $g['attr']['cHEIGHT'] / 0.2645; } if (isset($g['attr']['SERIES']) && strtolower($g['attr']['SERIES']) == 'rows') { $dataseries = 'rows'; } else { $dataseries = 'cols'; } // Defaults - define data $rowbegin = 2; $colbegin = 2; if ($type == 'scatter' || $type == 'xy') { if ($dataseries == 'rows') { $rowbegin = 1; } else { $colbegin = 1; } } $rowend = 0; $colend = 0; if (isset($g['attr']['DATA-ROW-BEGIN']) && ($g['attr']['DATA-ROW-BEGIN'] === '0' || $g['attr']['DATA-ROW-BEGIN'] > 0)) { $rowbegin = $g['attr']['DATA-ROW-BEGIN']; } if (isset($g['attr']['DATA-COL-BEGIN']) && ($g['attr']['DATA-COL-BEGIN'] === '0' || $g['attr']['DATA-COL-BEGIN'] > 0)) { $colbegin = $g['attr']['DATA-COL-BEGIN']; } if (isset($g['attr']['DATA-ROW-END']) && ($g['attr']['DATA-ROW-END'] === '0' || $g['attr']['DATA-ROW-END'] != 0)) { $rowend = $g['attr']['DATA-ROW-END']; } if (isset($g['attr']['DATA-COL-END']) && ($g['attr']['DATA-COL-END'] === '0' || $g['attr']['DATA-COL-END'] != 0)) { $colend = $g['attr']['DATA-COL-END']; } $nr = count($g['data']); $nc = 0; foreach ($g['data'] as $r) { $cc = 0; foreach ($r as $c) { $cc++; } $nc = max($nc, $cc); } if ($colend == 0) { $colend = $nc; } else { if ($colend < 0) { $colend = $nc + $colend; } } if ($rowend == 0) { $rowend = $nr; } else { if ($rowend < 0) { $rowend = $nr + $rowend; } } if ($colend < $colbegin) { $colend = $colbegin; } if ($rowend < $rowbegin) { $rowend = $rowbegin; } // if ($type == 'xy' || $type=='scatter') { $colstart=0; } // Get Data + Totals $data = array(); $totals = array(); for ($r = $rowbegin - 1; $r < $rowend; $r++) { for ($c = $colbegin - 1; $c < $colend; $c++) { if (isset($g['data'][$r][$c])) { $g['data'][$r][$c] = floatval($g['data'][$r][$c]); } else { $g['data'][$r][$c] = 0; } if ($dataseries == 'rows') { $data[$r + 1 - $rowbegin][$c + 1 - $colbegin] = $g['data'][$r][$c]; $totals[$r + 1 - $rowbegin] += $g['data'][$r][$c]; } else { $data[$c + 1 - $colbegin][$r + 1 - $rowbegin] = $g['data'][$r][$c]; if (isset($totals[$c + 1 - $colbegin])) { $totals[$c + 1 - $colbegin] += $g['data'][$r][$c]; } else { $totals[$c + 1 - $colbegin] = $g['data'][$r][$c]; } } } } // PERCENT if ($percent && $type != 'pie' && $type != 'pie3d') { for ($r = 0; $r < count($data); $r++) { for ($c = 0; $c < count($data[$r]); $c++) { $data[$r][$c] = $data[$r][$c] / $totals[$r] * 100; } } } // Get Legends and labels $legends = array(); $labels = array(); $longestlegend = 0; $longestlabel = 0; if ($dataseries == 'cols') { if ($colbegin > 1) { for ($r = $rowbegin - 1; $r < $rowend; $r++) { $legends[$r + 1 - $rowbegin] = $g['data'][$r][0]; $longestlegend = max($longestlegend, strlen($g['data'][$r][0])); } } if ($rowbegin > 1) { for ($c = $colbegin - 1; $c < $colend; $c++) { $labels[$c + 1 - $colbegin] = $g['data'][0][$c]; $longestlabel = max($longestlabel, strlen($g['data'][0][$c])); } } } else { if ($dataseries == 'rows') { if ($colbegin > 1) { for ($r = $rowbegin - 1; $r < $rowend; $r++) { $labels[$r + 1 - $rowbegin] = $g['data'][$r][0]; $longestlabel = max($longestlabel, strlen($g['data'][$r][0])); } } if ($rowbegin > 1) { for ($c = $colbegin - 1; $c < $colend; $c++) { $legends[$c + 1 - $colbegin] = $g['data'][0][$c]; $longestlegend = max($longestlegend, strlen($g['data'][0][$c])); } } } } // Default sizes $defsize = array(); $defsize['pie'] = array('w' => 600, 'h' => 300); $defsize['pie3d'] = array('w' => 600, 'h' => 300); $defsize['radar'] = array('w' => 600, 'h' => 300); $defsize['line'] = array('w' => 600, 'h' => 400); $defsize['xy'] = array('w' => 600, 'h' => 400); $defsize['scatter'] = array('w' => 600, 'h' => 400); $defsize['bar'] = array('w' => 600, 'h' => 400); $defsize['horiz_bar'] = array('w' => 600, 'h' => 500); // Use default ratios if ($w && !$h) { $h = $w * $defsize[$type]['h'] / $defsize[$type]['w']; } if ($h && !$w) { $w = $h * $defsize[$type]['w'] / $defsize[$type]['h']; } if (!$h && !$w) { $w = $defsize[$type]['w']; $h = $defsize[$type]['h']; } if (count($data) > 0 && $type) { $figure_file = "graph_cache/" . rand(11111, 999999999) . "." . $img_type; if ($bandw) { $colours = array('snow1', 'black', 'snow4', 'snow3', 'snow2', 'cadetblue4', 'cadetblue3', 'cadetblue1', 'bisque4', 'bisque2', 'beige'); } else { $colours = array('cyan', 'darkorchid4', 'cadetblue3', 'khaki1', 'darkolivegreen2', 'cadetblue4', 'coral', 'cyan4', 'rosybrown3', 'wheat1'); } $fills = array('navy', 'orange', 'red', 'yellow', 'purple', 'navy', 'orange', 'red', 'yellow', 'purple'); $patterns = array(PATTERN_DIAG1, PATTERN_CROSS1, PATTERN_STRIPE1, PATTERN_DIAG3, PATTERN_CROSS2, PATTERN_DIAG2, PATTERN_DIAG4, PATTERN_CROSS3, PATTERN_CROSS4, PATTERN_STRIPE1); $markers = array(MARK_DIAMOND, MARK_SQUARE, MARK_CIRCLE, MARK_UTRIANGLE, MARK_DTRIANGLE, MARK_FILLEDCIRCLE, MARK_CROSS, MARK_STAR, MARK_X); // LEGENDS if ($type == 'pie' || $type == 'pie3d') { $graph = new PieGraph($w * $k, $h * $k); } else { if ($type == 'radar') { $graph = new RadarGraph($w * $k, $h * $k); } else { $graph = new Graph($w * $k, $h * $k); } } // mPDF 4.5.009 // $graph->img->SetImgFormat($img_type) ; // if (strtoupper($img_type)=='JPEG') { $graph->img->SetQuality(90); } if ($antialias) { $graph->img->SetAntiAliasing(); } $graph->SetShadow(true, 2 * $k); $graph->SetMarginColor("white"); // TITLE $graph->title->Set($title); $graph->title->SetMargin(10 * $k); $graph->title->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); $graph->title->SetColor("black"); $graph->legend->SetLineSpacing(3 * $k); $graph->legend->SetMarkAbsSize(6 * $k); $graph->legend->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); // Set GRAPH IMAGE MARGINS if ($type == 'pie' || $type == 'pie3d') { $psize = 0.3; $pposxabs = $w / 2; $pposy = 0.55; if ($longestlegend) { // if legend showing $pposxabs -= ($longestlegend * 5 + 20) / 2; } $pposx = $pposxabs / $w; $graph->legend->Pos(0.02, 0.5, 'right', 'center'); } else { if ($type == 'radar') { $psize = 0.5; $pposxabs = $w / 2; $pposy = 0.55; if ($longestlabel) { // if legend showing $pposxabs -= ($longestlabel * 5 + 20) / 2; } $pposx = $pposxabs / $w; $graph->legend->Pos(0.02, 0.5, 'right', 'center'); } else { if ($type == 'xy' || $type == 'scatter') { $pml = 50; $pmr = 20; $pmt = 60; $pmb = 50; $xaxislblmargin = $pmb - 30; $yaxislblmargin = $pml - 15; $graph->legend->Pos(0.02, 0.1, 'right', 'top'); } else { if ($type == 'line' || $type == 'bar') { $pml = 50; $pmr = 20; $pmt = 60; $pmb = 50; $xlangle = 0; $ll = $longestlegend * 5; // 45 degrees 8pt fontsize if ($ll > 5 || $ll > 3 && count($data) > 10) { $pmb = max($pmb, $ll + 30); $xlangle = 50; } $xaxislblmargin = $pmb - 30; $yaxislblmargin = $pml - 15; if ($longestlabel && !$overlap) { // if legend showing $pmr = $longestlabel * 5 + 40; } $graph->legend->Pos(0.02, 0.1, 'right', 'top'); } else { if ($type == 'horiz_bar') { $pml = 50; $pmr = 20; $pmt = 50; $pmb = 45; $ll = $longestlegend * 6.5; // 8pt fontsize $pml = max($pml, $ll + 20); $xaxislblmargin = $pml - 20; $yaxislblmargin = $pmb - 15; if ($longestlabel && !$overlap) { // if legend showing $pmr = $longestlabel * 5 + 40; } $graph->legend->Pos(0.02, 0.1, 'right', 'top'); } } } } } // DRAW THE GRAPHS if ($type == 'pie') { $p1 = new PiePlot($data[0]); $p1->SetSliceColors($colours); if ($show_values) { $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent) { $p1->SetLabelType(PIE_VALUE_PERADJ); } else { $p1->SetLabelType(PIE_VALUE_ABS); } if ($percent || $show_percent) { $p1->value->SetFormat("%d%%"); } else { $p1->value->SetFormat("%s"); } // Enable and set policy for guide-lines. Make labels line up vertically $p1->SetGuideLines(true); $p1->SetGuideLinesAdjust(1.5); } else { $p1->value->Show(false); } $p1->SetLegends($legends); $p1->SetSize($psize); $p1->SetCenter($pposx, $pposy); if ($labels[0]) { $graph->subtitle->Set($labels[0]); $graph->subtitle->SetMargin(10 * $k); $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); $graph->subtitle->SetColor("black"); } $graph->Add($p1); } else { if ($type == 'pie3d') { $p1 = new PiePlot3d($data[0]); $p1->SetSliceColors($colours); if ($show_values) { $p1->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent) { $p1->SetLabelType(PIE_VALUE_PERADJ); } else { $p1->SetLabelType(PIE_VALUE_ABS); } if ($percent || $show_percent) { $p1->value->SetFormat("%d%%"); } else { $p1->value->SetFormat("%s"); } } else { $p1->value->Show(false); } $p1->SetLegends($legends); $p1->SetEdge(); $p1->SetSize($psize); $p1->SetCenter($pposx, $pposy); if ($labels[0]) { $graph->subtitle->Set($labels[0]); $graph->subtitle->SetMargin(10 * $k); $graph->subtitle->SetFont(FF_USERFONT, FS_BOLD, 11 * $k); $graph->subtitle->SetColor("black"); } $graph->Add($p1); } else { if ($type == 'radar') { $graph->SetSize($psize); $graph->SetPos($pposx, $pposy); $graph->SetTitles($legends); // labels each axis $graph->axis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->axis->title->SetMargin(5 * $k); $graph->axis->SetWeight(1 * $k); $graph->axis->HideLabels(); $graph->axis->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k); $graph->HideTickMarks(); $group = array(); foreach ($data as $series => $dat) { $rdata = array(); foreach ($data[$series] as $row) { $rdata[] = $row; } if (count($rdata) < 3) { die("ERROR::Graph::Cannot create a Radar Plot with less than 3 data points."); } // Create the radar plot $bplot = new RadarPlot($rdata); $bplot->mark->SetType($markers[$series]); $bplot->mark->SetFillColor($colours[$series]); $bplot->mark->SetWidth(3 * $k); $bplot->SetColor($colours[$series]); if ($series == 0) { $bplot->SetFillColor('lightred'); } else { $bplot->SetFill(false); } $bplot->SetLineWeight(1 * $k); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } $graph->Add($bplot); } } else { if ($type == 'line') { // Setup the graph. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB $graph->SetScale($axes); $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($ylabel) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitle($ylabel, 'middle'); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); } $graph->yaxis->SetLabelMargin(4 * $k); if ($percent || $show_percent) { $graph->yaxis->SetLabelFormat('%d%%'); } // Percent // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(true); if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelAngle($xlangle); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($xlabel) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitle($xlabel, 'middle'); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); } foreach ($data as $series => $rdata) { $bplot = new LinePlot($rdata); $bplot->mark->SetType($markers[$series]); $bplot->mark->SetFillColor($colours[$series]); $bplot->mark->SetWidth(4 * $k); if ($show_values) { $bplot->value->Show(); // Not if scatter $bplot->value->SetMargin(6 * $k); $bplot->value->SetColor("darkred"); $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent || $show_percent) { $bplot->value->SetFormat('%d%%'); } else { $bplot->value->SetFormat("%s"); } } // Set color for each line $bplot->SetColor($colours[$series]); $bplot->SetWeight(2 * $k); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } // Indent the X-scale so the first and last point doesn't fall on the edges $bplot->SetCenter(); $graph->Add($bplot); } } else { if ($type == 'xy' || $type == 'scatter') { // Setup the graph. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB $graph->SetScale($axes); // Setup font for axis $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); // Y-axis title if ($labels[1]) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); $graph->yaxis->SetTitle($labels[1], 'middle'); } $graph->yaxis->SetLabelMargin(4 * $k); if ($percent || $show_percent) { $graph->yaxis->SetLabelFormat('%d%%'); } // Percent // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(true); // Just let the maximum be autoscaled $graph->yaxis->scale->SetAutoMin(0); if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); // mPDF 2.5 Corrects labelling of x-axis // $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelAngle(50); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($labels[0]) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); $graph->xaxis->SetTitle($labels[0], 'middle'); } // Create the bar plot // SPLINES if ($splines && $type == 'xy') { $spline = new Spline($data[0], $data[1]); list($newx, $newy) = $spline->Get(100); } else { $newx = $data[0]; $newy = $data[1]; } if ($type == 'xy') { // LINE PLOT $bplot = new LinePlot($newy, $newx); // Set color for each line $bplot->SetColor($fills[0]); $bplot->SetWeight(4 * $k); if ($bandw) { $bplot->SetShadow("gray5"); } $graph->Add($bplot); } // SCATTER PLOT $cplot = new ScatterPlot($data[1], $data[0]); $cplot->mark->SetType($markers[0]); $cplot->mark->SetFillColor($fills[0]); $cplot->mark->SetWidth(8 * $k); if ($show_values) { // mPDF 2.5 if ($type == 'xy') { $cplot->value->Show(); } // Not if scatter $cplot->value->SetMargin(8 * $k); $cplot->value->SetColor("darkred"); $cplot->value->SetFont(FF_USERFONT, FS_NORMAL, 6 * $k); if ($percent || $show_percent) { $cplot->value->SetFormat('%d%%'); } else { $cplot->value->SetFormat("%s"); } } // Set color for each line $cplot->SetColor($fills[0]); $cplot->SetWeight(4 * $k); if ($bandw) { $cplot->SetShadow("gray5"); } $graph->Add($cplot); } else { if ($type == 'bar') { // Setup the graph. $graph->img->SetMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB $graph->SetScale($axes); // Setup y-axis $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } $graph->yaxis->SetLabelMargin(4 * $k); if ($ylabel) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitle($ylabel, 'middle'); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); } // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(false); // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelAngle($xlangle); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($xlabel) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitle($xlabel, 'middle'); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); } $group = array(); foreach ($data as $series => $dat) { $rdata = array(); foreach ($data[$series] as $row) { $rdata[] = $row; } // Create the bar plot $bplot = new BarPlot($rdata); $bplot->SetWidth(0.6); // for SINGLE?? // Setup color for gradient fill style if ($bandw) { $bplot->SetPattern($patterns[$series]); } else { $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION); } // Set color for the frame of each bar $bplot->SetColor("darkgray"); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } if ($show_values) { $bplot->value->Show(); $bplot->value->SetMargin(6 * $k); $bplot->value->SetColor("darkred"); $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent || $show_percent) { $bplot->value->SetFormat('%d%%'); } else { $bplot->value->SetFormat("%s"); } } $group[] = $bplot; } if (count($data) == 1) { $graph->Add($group[0]); } else { // Create the grouped bar plot if ($stacked) { $gbplot = new AccBarPlot($group); } else { $gbplot = new GroupBarPlot($group); } $graph->Add($gbplot); } } else { if ($type == 'horiz_bar') { $graph->SetScale($axes); $graph->Set90AndMargin($pml * $k, $pmr * $k, $pmt * $k, $pmb * $k); // LRTB // Setup y-axis $graph->yaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetLabelMargin(4 * $k); $graph->yaxis->SetPos('max'); // Intersect at top of x-axis i.e. y axis is at bottom // First make the labels look right $graph->yaxis->SetLabelAlign('center', 'top'); if ($percent || $show_percent) { $graph->yaxis->SetLabelFormat('%d%%'); } $graph->yaxis->SetLabelSide(SIDE_RIGHT); $graph->yaxis->scale->SetGrace(10); // sets 10% headroom if ($hide_y_axis) { $graph->yaxis->Hide(); } if ($hide_grid) { $graph->ygrid->Show(false); } // The fix the tick marks $graph->yaxis->SetTickSide(SIDE_LEFT); if ($ylabel) { $graph->yaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->yaxis->SetTitle($ylabel, 'middle'); $graph->yaxis->SetTitleMargin($yaxislblmargin * $k); // Finally setup the title $graph->yaxis->SetTitleSide(SIDE_RIGHT); // To align the title to the right use : $graph->yaxis->title->Align('right'); $graph->yaxis->title->SetAngle(0); } // Show 0 label on Y-axis (default is not to show) $graph->yscale->ticks->SupressZeroLabel(false); // Setup X-axis labels $graph->xaxis->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->title->SetAngle(90); $graph->xaxis->SetTickLabels($legends); $graph->xaxis->SetLabelMargin(4 * $k); // X-axis title if ($xlabel) { $graph->xaxis->title->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); $graph->xaxis->SetTitleMargin($xaxislblmargin * $k); $graph->xaxis->SetTitle($xlabel, 'middle'); } $group = array(); foreach ($data as $series => $dat) { $rdata = array(); foreach ($data[$series] as $row) { $rdata[] = $row; } // Create the bar pot $bplot = new BarPlot($rdata); $bplot->SetWidth(0.6); // for SINGLE?? // Setup color for gradient fill style if ($bandw) { $bplot->SetPattern($patterns[$series]); } else { $bplot->SetFillGradient($fills[$series], "#EEEEEE", GRAD_LEFT_REFLECTION); } // Set color for the frame of each bar $bplot->SetColor("darkgray"); $bplot->SetLegend($labels[$series]); if ($bandw) { $bplot->SetShadow("gray5"); } if ($show_values) { $bplot->value->Show(); $bplot->value->SetMargin(6 * $k); $bplot->value->SetColor("darkred"); $bplot->value->SetFont(FF_USERFONT, FS_NORMAL, 8 * $k); if ($percent || $show_percent) { $bplot->value->SetFormat('%d%%'); } else { $bplot->value->SetFormat("%s"); } } $group[] = $bplot; } if (count($data) == 1) { $graph->Add($group[0]); } else { // Create the grouped bar plot if ($stacked) { $gbplot = new AccBarPlot($group); } else { $gbplot = new GroupBarPlot($group); } $graph->Add($gbplot); } } } } } } } } if ($graph) { $graph->Stroke(_MPDF_PATH . $figure_file); $srcpath = str_replace("\\", "/", dirname(__FILE__)) . "/"; $srcpath .= $figure_file; return array('file' => $srcpath, 'w' => $w, 'h' => $h); } } return false; }
function graphHistogram($pDB, $smarty, $module_name, $local_templates_dir) { include "libs/jpgraph/jpgraph.php"; include "libs/jpgraph/jpgraph_line.php"; // Tipo de llamada Entrante o Saliente if (!isset($_GET['tipo'])) { return ''; } $sTipoLlamada = $_GET['tipo']; if (!in_array($sTipoLlamada, array('E', 'S'))) { return ''; } // Fechas inicial y final del rango if (!isset($_GET['fecha_ini'])) { return ''; } if (!isset($_GET['fecha_fin'])) { return ''; } $sFechaInicial = $_GET['fecha_ini']; $sFechaFinal = $_GET['fecha_fin']; $sFormatoFecha = '^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}$'; if (!ereg($sFormatoFecha, $sFechaInicial)) { return ''; } if (!ereg($sFormatoFecha, $sFechaFinal)) { return ''; } // Recuperar la lista de llamadas $arrCalls = array(); $oCalls = new paloSantoCallsHour($pDB); $arrCalls['todas'] = $oCalls->getCalls($sTipoLlamada, 'T', $sFechaInicial, $sFechaFinal); if (!is_array($arrCalls['todas'])) { return $oCalls->errMsg; } $arrCalls['exitosas'] = $oCalls->getCalls($sTipoLlamada, 'E', $sFechaInicial, $sFechaFinal); if (!is_array($arrCalls['exitosas'])) { return $oCalls->errMsg; } $arrCalls['abandonadas'] = $oCalls->getCalls($sTipoLlamada, 'A', $sFechaInicial, $sFechaFinal); if (!is_array($arrCalls['abandonadas'])) { return $oCalls->errMsg; } // Validación de la cola graficada $sQueue = ''; if (isset($_GET['queue'])) { $sQueue = $_GET['queue']; } if (!in_array($sQueue, array_keys($arrCalls['todas']))) { $sQueue = ''; } $listaVacia = array_fill(0, 24, 0); $graphdata = array(); if ($sQueue != '') { $graphdata['todas'] = $arrCalls['todas'][$sQueue]; // Por definición, siempre existe $graphdata['exitosas'] = isset($arrCalls['exitosas'][$sQueue]) ? $arrCalls['exitosas'][$sQueue] : $listaVacia; $graphdata['abandonadas'] = isset($arrCalls['abandonadas'][$sQueue]) ? $arrCalls['abandonadas'][$sQueue] : $listaVacia; } else { $graphdata['todas'] = $listaVacia; $graphdata['exitosas'] = $listaVacia; $graphdata['abandonadas'] = $listaVacia; foreach (array('todas', 'exitosas', 'abandonadas') as $k) { foreach ($arrCalls[$k] as $sQueue => $hist) { $graphdata[$k] = array_map('sumar', $graphdata[$k], $hist); } } } // Labels $datahours = array(); for ($i = 0; $i < 24; $i++) { $datahours[] = sprintf('%02d', $i); } // Setup the graph $graph = new Graph(800, 500); $graph->SetMarginColor('white'); $graph->SetScale("textlin"); $graph->SetFrame(true); $graph->SetMargin(60, 50, 30, 30); $graph->title->Set(_tr('Calls')); $graph->yaxis->HideZeroLabel(); $graph->ygrid->SetFill(true, '#EFEFEF@0.5', '#BBCCFF@0.5'); $graph->xgrid->Show(); $graph->xaxis->SetTickLabels($datahours); // Create the first line $p1 = new LinePlot($graphdata['todas']); $p1->SetColor("navy"); $p1->SetLegend(_tr('All')); $p1->SetWeight(7); $graph->Add($p1); // Create the second line $p2 = new LinePlot($graphdata['exitosas']); $p2->SetColor("red"); $p2->SetLegend(_tr('Completed')); $p2->SetWeight(3); $graph->Add($p2); // Create the third line $p3 = new LinePlot($graphdata['abandonadas']); $p3->SetColor("orange"); $p3->SetLegend(_tr('Abandoned')); $p3->SetWeight(3); $graph->Add($p3); $graph->legend->SetShadow('gray@0.4', 5); $graph->legend->SetPos(0.1, 0.1, 'right', 'top'); // Output line $graph->Stroke(); }
<?php // content="text/plain; charset=utf-8" require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $datay = array(20, 15, 33, 5, 17, 35, 22); // Setup the graph $graph = new Graph(400, 200); $graph->SetMargin(40, 40, 20, 30); $graph->SetScale("intlin"); $graph->SetMarginColor('darkgreen@0.8'); $graph->title->Set('Gradient filled line plot'); $graph->yscale->SetAutoMin(0); // Create the line $p1 = new LinePlot($datay); $p1->SetColor("blue"); $p1->SetWeight(0); $p1->SetFillGradient('red', 'yellow'); $graph->Add($p1); // Output line $graph->Stroke(); ?>
// Setup the scales for X,Y and Y2 axis $graph->SetScale("intlin"); // X and Y axis $graph->SetY2Scale("lin"); // Y2 axis // Overall graph title $graph->title->Set('Synchronized Y & Y2 scales'); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); // Title for X-axis $graph->xaxis->title->Set('Measurement'); $graph->xaxis->title->SetMargin(5); $graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 11); // Create Y data set $lplot = new LinePlot($datay); $graph->yaxis->title->Set('Celcius (C)'); $graph->yaxis->title->SetMargin(5); $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 11); // ... and add the plot to the Y-axis $graph->Add($lplot); // Create Y2 scale data set $l2plot = new LinePlot($datay); $l2plot->SetWeight(0); $graph->y2axis->title->Set('Fahrenheit (F)'); $graph->y2axis->title->SetMargin(5); // Some extra margin to clear labels $graph->y2axis->title->SetFont(FF_ARIAL, FS_NORMAL, 11); $graph->y2axis->SetLabelFormatCallback('toFahrenheit'); $graph->y2axis->SetColor('navy'); // ... and add the plot to the Y2-axis $graph->AddY2($l2plot); $graph->Stroke();
} $x[$i] = str_pad($crhour, 2, $hr_pad, STR_PAD_LEFT) . ":" . str_pad($crmin, 2, "0", STR_PAD_LEFT); } $datax = $x; // Create the graph. These two calls are always required $graph = new Graph($xsize, $ysize, "auto", 30); $graph->SetScale("textlin"); $graph->yaxis->scale->SetGrace(10); $graph->SetMarginColor("{$margincolour}"); // Add a drop shadow $graph->SetShadow(); // Adjust the margin a bit to make more room for titles $graph->SetMargin($lm, $rm, $tm, $bm); // Create a line plot $lplot = new LinePlot($datay); $lplot->SetWeight(2); $lplot->SetColor("{$speed_col}"); $graph->Add($lplot); // titles $graph->title->SetFont(FF_ARIAL, FS_BOLD, 10); $graph->title->Set("{$txt_wind_sp} {$txt_60m} ({$speed_unit})"); $graph->title->SetColor("{$textcolour}"); //x-axis $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, 8); $graph->xaxis->SetFont(FF_ARIAL, FS_BOLD, 8); $graph->xaxis->SetTitlemargin(25); $graph->xaxis->SetLabelMargin(10); $graph->xaxis->SetTickLabels($datax); $graph->xaxis->SetLabelAngle($label_angle); $graph->xaxis->SetTextLabelInterval($label_interval); $graph->xaxis->SetPos("min");
$tmp += $ydata[$i - $j]; $tmp += $ydata[$i + $j]; } $tmp += $ydata[$i]; //echo $tmp . '<br />'; $div = $prec * 2 + 1; if ($i - $prec < 0) { $div = $prec + $i + 1; } if ($i + $prec > count($ydata)) { $div = count($ydata) - 1 - $i + $prec + 1; } $avg[$i] = $tmp / $div; } $trendline = new LinePlot($avg, $xdata); $trendline->SetWeight(2); $graph->AddLine($trendline); } //Weekends if ($starttime > strtotime('-13 months', $endtime)) { for ($i = 0; $i < count($xdata); $i++) { $rtime = $xdata[$i]; //get start time of this day $start = mktime(0, 0, 0, date('n', $rtime), date('j', $rtime), date('Y', $rtime)); if (date('w', $rtime) == 6) { $end = $start + 60 * 60 * 24 * 2; $band = new PlotBand(VERTICAL, BAND_SOLID, $start, $end, 'lightgray@0.7'); $band->ShowFrame(false); $graph->add($band); } $year = date('Y', $rtime);
<?php include "../jpgraph.php"; include "../jpgraph_line.php"; $f = new FuncGenerator('cos($i)', '$i*$i*$i'); list($xdata, $ydata) = $f->E(-M_PI, M_PI, 25); $graph = new Graph(350, 430, "auto"); $graph->SetScale("linlin"); $graph->SetShadow(); $graph->img->SetMargin(50, 50, 60, 40); $graph->SetBox(true, 'black', 2); $graph->SetMarginColor('white'); $graph->SetColor('lightyellow'); $graph->SetAxisStyle(AXSTYLE_BOXIN); $graph->xgrid->Show(); //$graph->xaxis->SetLabelFormat('%.0f'); $graph->img->SetMargin(50, 50, 60, 40); $graph->title->Set("Function plot"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->subtitle->Set("(BOXIN Axis style)"); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); $lp1 = new LinePlot($ydata, $xdata); $lp1->SetColor("blue"); $lp1->SetWeight(2); $graph->Add($lp1); $graph->Stroke(); ?>
function draw_usage() { $w = 400; $h = 300; $graph = new Graph($w, $h); $graph->SetScale('intlin', 0, 50); $graph->SetMargin(40, 40, 40, 60); $graph->title->Set('Data Usage'); $graph->xaxis->title->Set('User'); $graph->yaxis->title->Set('Usage'); $graph->xaxis->SetTickLabels(array('1', '2', '3')); $lineplot = new LinePlot(array('10', '12', '14')); $lineplot->SetColor('blue'); $lineplot->SetWeight(2); $lineplot->value->Show(); $bmi_under = new LinePlot(array('15', '25', '30')); $bmi_under->SetColor('yellow'); $bmi_under->SetWeight(3); $bmi_normal = new LinePlot(array('15', '25', '30')); $bmi_normal->SetColor('green'); $bmi_normal->SetWeight(3); $bmi_over = new LinePlot(array('10', '40', '45')); $bmi_over->SetColor('red'); $bmi_over->SetWeight(3); $lineplot->SetLegend('Actual BMI'); $bmi_under->SetLegend('Normal'); $bmi_normal->SetLegend('Overweight'); $bmi_over->SetLegend('Obese'); $graph->legend->SetLayout(LEGEND_HOR); $graph->legend->Pos(0.5, 0.99, 'center', 'bottom'); $graph->Add($bmi_under); $graph->Add($bmi_normal); $graph->Add($bmi_over); $graph->Add($lineplot); $graph->Stroke(); }
pg_close($coop); include "../../../include/jpgraph/jpgraph.php"; include "../../../include/jpgraph/jpgraph_bar.php"; include "../../../include/jpgraph/jpgraph_line.php"; include "../../../include/network.php"; $nt = new NetworkTable("IACLIMATE"); $cities = $nt->table; $graph = new Graph(600, 400, "example1"); $graph->SetScale("textlin", 0, 100); $graph->img->SetMargin(40, 5, 35, 60); $graph->xaxis->SetTickLabels($xdata); $graph->xaxis->SetTextTickInterval(100); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetTitle("Precip [inches]"); $graph->xaxis->SetTitleMargin(30); $graph->yaxis->SetTitle("Cumulative Distribution (percent)"); $graph->title->Set($cities[$station]['name'] . " Precip Accumulation Probabilities"); $graph->subtitle->Set($subtitle); $l1 = new LinePlot($ydata); $l1->SetColor("blue"); $l1->SetWeight(2); $l1->AddArea($hm, $hm, LP_AREA_FILLED, "lightred"); $l1->AddArea($h95, $h95, LP_AREA_FILLED, "lightred"); $l1->AddArea($h5, $h5, LP_AREA_FILLED, "lightred"); $txt = new Text("Diagnostics\n Min: {$lowVal} ({$lowYear})\n 95%: " . ($lowVal + $h95 * 0.01) . "\n~Mean: " . ($lowVal + $hm * 0.01) . "\n SD: {$stddev}\n 5%: " . ($lowVal + $h5 * 0.01) . "\n Max: {$hiVal} ({$hiYear})\n"); $txt->SetPos(0.71, 0.128); $txt->SetFont(FF_FONT1, FS_NORMAL); $txt->SetColor("blue"); $graph->Add($l1); $graph->Add($txt); $graph->Stroke();
$found = true; } } 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);
// content="text/plain; charset=utf-8" require_once "jpgraph/jpgraph.php"; 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);
require_once 'jpgraph/jpgraph_log.php'; // Matrix size rxr $r = 10; // Max Interpolation factor $f = 5; for ($i = 1; $i <= $f; ++$i) { $xdata[] = $i; $ydata[] = pow($r * pow(2, $i - 1) - (pow(2, $i) - 1), 2); } $graph = new Graph(400, 240); $graph->SetScale('intlog'); $graph->SetMargin(50, 50, 20, 30); $graph->SetFrame(false); $graph->SetBox(true, 'black', 2); $graph->SetMarginColor('white'); $graph->SetColor('lightyellow@0.7'); $graph->title->Set('Interpolation growth for size 10x10'); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->SetTitle('Interpolation factor', 'center'); $graph->xaxis->SetTitleMargin(10); $graph->SetAxisStyle(AXSTYLE_YBOXIN); $graph->xgrid->Show(); $lp1 = new LinePlot($ydata, $xdata); $lp1->SetColor('darkred'); $lp1->SetWeight(3); $graph->Add($lp1); $graph->Stroke(); ?>