function graficoBarra($data, $archivo = "", $meta_data = array('titulo' => 'Sin Título', 'tituloX' => 'Eje X', 'tituloY' => 'Eje Y', 'color' => 'SkyBlue', 'width' => 800, 'height' => 600, 'angle' => 45), $legend = array("Datos")) { # Objeto que crea el gráfico y su tama?o $plot = new PHPlot($meta_data['width'], $meta_data['height']); $plot->SetImageBorderType('plain'); # Setea el archivo donde se guarda la imagen generada y no permite la visualización inmediata $plot->SetPrintImage(false); $plot->SetFileFormat("jpg"); $plot->SetOutputFile($archivo); $plot->SetIsInline(true); # Envio de datos $plot->SetDataValues($data); # Tipo de gráfico y datos $plot->SetDataType("text-data"); $plot->SetPlotType("bars"); # Setiando el True type font //$plot->SetTTFPath(TTFPath); //$plot->SetUseTTF(TRUE); $plot->SetAxisFontSize(2); $plot->SetVertTickIncrement(7); //$plot->SetXTickLength(7); //$plot->SetDataColors($meta_data['color']); $plot->SetDataColors(array($meta_data['color'], 'red', 'white')); $plot->SetLegendPixels(1, 1); $plot->SetLegend($legend); # Etiquetas del eje Y: $plot->SetYTitle($meta_data['tituloY']); $plot->SetYDataLabelPos('plotin'); # Título principal del gráfico: $plot->SetTitle($meta_data['titulo']); # Etiquetas eje X: $plot->SetXTitle($meta_data['tituloX']); if (isset($meta_data['angle'])) { $plot->SetXLabelAngle($meta_data['angle']); } else { $plot->SetXLabelAngle(45); } $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Método que dibuja el gráfico $plot->DrawGraph(); $plot->PrintImage(); }
$p->SetFont('legend', $tp['legendfont'], $tp['ttfsize']); } else { $p->SetFont('legend', $tp['ttfont'], $tp['ttfsize']); } } elseif (isset($tp['legendfont'])) { $p->SetFont('legend', $tp['legendfont']); } $p->SetLegend($tp['text']); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('lines'); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(1.0); $p->SetYTickIncrement(1.0); if (isset($tp['textalign'])) { if (isset($tp['colorboxalign'])) { $p->SetLegendStyle($tp['textalign'], $tp['colorboxalign']); } else { $p->SetLegendStyle($tp['textalign']); } } if (isset($tp['px']) && isset($tp['py'])) { $p->SetLegendPixels($tp['px'], $tp['py']); } if (isset($tp['wx']) && isset($tp['wy'])) { $p->SetLegendWorld($tp['wx'], $tp['wy']); } if (isset($tp['cbwa'])) { $p->legend_colorbox_width = $tp['cbwa']; } $p->DrawGraph();
$sSQL6a = "Select sum(cantidad) as c From cargosCuentaPaciente where\n entidad='" . $entidad . "'\n and\nalmacenIngreso='" . $almacenIngreso . "'\nand\n\n\nmes='" . $mes . "'\nand\nyear='" . $year . "'\nand\nnaturaleza='C'\nand\ngpoProducto='" . $gpoProducto . "'\nand\n\nstatusPC='" . $myrow2['tipo'] . "'\n"; $result6a = mysql_db_query($basedatos, $sSQL6a); $myrow6a = mysql_fetch_array($result6a); $sSQL6ad = "Select sum(cantidad) as c From cargosCuentaPaciente where\n\nentidad='" . $entidad . "'\n and\nalmacenIngreso='" . $almacenIngreso . "'\nand\n\nmes='" . $mes . "'\nand\nyear='" . $year . "'\nand\nnaturaleza='A'\nand\ngpoProducto='" . $gpoProducto . "'\nand\n\nstatusPC='" . $myrow2['tipo'] . "'\n"; $result6ad = mysql_db_query($basedatos, $sSQL6ad); $myrow6ad = mysql_fetch_array($result6ad); echo mysql_error(); //******************************************* $total = $myrow6a['c'] - $myrow6ad['c']; $data[] = array($myrow2['descripcion'], $total); } $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); $plot->SetPlotType('pie'); $plot->SetDataType('text-data-single'); $plot->SetDataValues($data); # Set enough different colors; $plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'brown', 'lavender', 'pink', 'gray', 'orange')); # Main plot title: $plot->SetTitle("ESTADISTICA DE PORCENTAJE Y TIPOS"); # Build a legend from our data array. # Each call to SetLegend makes one line as "label: value". foreach ($data as $row) { $plot->SetLegend(implode(': ', $row)); } # Place the legend in the upper left corner: $plot->SetLegendPixels(5, 5); $plot->DrawGraph(); ?>
//text-data (no time) $example_data = array($data_array, $data_array); } else { //data-data (any extra entries are time). $example_data = array($data_array); } $graph->SetDataValues($example_data); //Error_Reporting(0); $graph->SetPlotType($graph_type_str); $graph->SetLabelScalePosition(1.27); $graph->SetLegend($legend_array); if ($graph_type == 2) { $graph->SetYLabel($element); $graph->SetXLabel($cw['users']); } else { $graph->SetLegendPixels(1, 1, ""); } //$graph->SetTitle("$element per user"); //Draw it $graph->DrawGraph(); //list things to change on the graph } else { print_header($cw['graphs']); if (isset($graph_selected) && $graph_selected == 1) { echo sprintf($st[143], $element) . "<img src='{$_SERVER['PHP_SELF']}?graph_db={$graph_db}&draw_graph=1&graph_type={$graph_type}&remaining={$remaining}' alt='" . sprintf($st[144], $graph_type_str, $element) . "' /><br />" . $st[145] . "</center>"; } else { $graph_selected = 0; } $type_link = "<a href={$_SERVER['PHP_SELF']}?graph_db={$graph_db}&element={$element}&graph_selected={$graph_selected}&remaining={$remaining}&graph_type="; echo sprintf($st[146], $graph_type_str, $type_link, $type_link); echo $st[147] . " <a href='{$_SERVER['PHP_SELF']}?graph_db={$graph_db}&element={$element}&graph_selected={$graph_selected}&remaining=1&graph_type={$graph_type}'>" . $cw['yes'] . "</a> - <a href='{$_SERVER['PHP_SELF']}?graph_db={$graph_db}&element={$element}&graph_selected={$graph_selected}&remaining=0&graph_type={$graph_type}'>No</a><br />";
whole numbers. */ $data = array(); # This is a cubic equation with roots at -8, 2, 10 for ($x = -10; $x <= 10; $x++) { $data[] = array('', $x, ($x + 8) * ($x - 2) * ($x - 10)); } $p = new PHPlot(400, 800); $p->SetPrintImage(FALSE); $p->SetPlotBorderType('full'); $p->SetTitle("Set/Reset Parameters Test (2)\n" . "Top: Parameters Set\n" . "Bottom: Parameters Reset"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('lines'); $p->SetLegend('Y = F(X)'); $p->SetLegendPixels(100, 200); $p->SetNumXTicks(5); $p->SetNumYTicks(8); $p->SetXTitle('X Axis with 5 ticks'); $p->SetYTitle('Y Axis with 8 ticks'); $p->SetXAxisPosition(-228); $p->SetYAxisPosition(7); $p->SetPlotAreaPixels(70, 80, 380, 400); $p->DrawGraph(); $p->SetLegendPixels(); $p->SetNumXTicks(); $p->SetNumYTicks(); $p->SetXTitle('X Axis'); $p->SetYTitle('Y Axis'); $p->SetXAxisPosition(); $p->SetYAxisPosition();
function costo_externo_interno_año($id_oficina, $año) { $this->autoLayout = false; $this->autoRender = false; $this->loadModel('CentroCosto'); $sql_oficina = ''; if ($id_oficina != 0) { $sql_oficina = " AND Cencos_id='" . $id_oficina . "' "; $cenco = $this->CentroCosto->find('first', array('fields' => array('CentroCosto.Cencos_nombre'), 'conditions' => array('CentroCosto.Cencos_id' => $id_oficina))); $subtitulo_oficina = 'la dependencia ' . mb_convert_case($cenco['CentroCosto']['Cencos_nombre'], MB_CASE_TITLE, "UTF-8"); } else { $subtitulo_oficina = 'todas las dependencias'; } $meses = $this->Solicitud->query("SELECT MONTH(solucionada) AS mes FROM solicitudes WHERE estado='s' " . $sql_oficina . " AND YEAR(solucionada)=" . $año . " GROUP BY MONTH(solucionada)"); if (!empty($meses)) { // Inicializamos el arreglo en ceros (para los meses ke no tienen solicitudes). $totales = array(); for ($i = 1; $i <= 12; $i++) { $totales[$i][0][0] = array('costo_i' => 0, 'costo_e' => 0); } foreach ($meses as $mes) { $costos_e_i = $this->Solicitud->query("SELECT SUM(costo_externo) AS costo_e, SUM(costo_interno) AS costo_i FROM solicitudes WHERE estado='s' AND YEAR(solucionada)=" . $año . " AND MONTH(solucionada)=" . $mes[0]['mes']); $totales[$mes[0]['mes']] = $costos_e_i; } if (!empty($totales)) { $total_costo_interno = $total_costo_externo = 0; $i = 0; $arreglo_plot = array(); foreach ($totales as $mes => $arreglo_mes) { // se construye el array para el PHPlot. if (count($arreglo_mes) > 0) { $arreglo_plot[$i] = array($this->meses[$mes], $arreglo_mes[0][0]['costo_i'], $arreglo_mes[0][0]['costo_e']); $total_costo_interno += $arreglo_mes[0][0]['costo_i']; $total_costo_externo += $arreglo_mes[0][0]['costo_e']; } else { $arreglo_plot[$i] = array($this->meses[$mes], 0, 0); } $i++; } $plot = new PHPlot(1790, 500); $plot->SetDataValues($arreglo_plot); $plot->SetDataType('text-data'); // Fuentes $plot->SetUseTTF(true); $plot->SetFontTTF('legend', 'FreeSans.ttf', 9); $plot->SetFontTTF('title', 'FreeSans.ttf', 14); $plot->SetFontTTF('y_label', 'FreeSans.ttf', 9); $plot->SetFontTTF('x_label', 'FreeSans.ttf', 10); $plot->SetFontTTF('y_title', 'FreeSans.ttf', 14); $plot->SetFontTTF('x_title', 'FreeSans.ttf', 12); // Titulos $plot->SetTitle("\nTotal de costos internos/externos\n" . "de " . $subtitulo_oficina . " en el año " . $año . "\n TOTAL Costo Interno = \$" . $total_costo_interno . "\n" . "TOTAL Costo Externo = \$" . $total_costo_externo); $plot->SetYTitle('$ COSTO'); // Etiquetas $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetDrawXGrid(true); // Leyenda $leyenda = array('Costo Interno', 'Costo Externo'); $plot->SetLegend($leyenda); $plot->SetLegendPixels(27, 0); $plot->SetDataColors(array('beige', 'YellowGreen')); $plot->SetPlotType('bars'); $plot->SetShading(5); $plot->DrawGraph(); } } }
<?php # PHPlot Example - Horizontal Stacked Bars require_once 'phplot.php'; $column_names = array('Beef', 'Fish', 'Pork', 'Chicken', 'Butter', 'Cheese', 'Ice Cream'); // | | | | | | | $data = array(array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9), array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.699999999999999), array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4), array('1970', 79.59999999999999, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8), array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8)); $plot = new PHPlot(800, 500); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetTitle("U.S. Annual Per-Capita Consumption\n" . "of Selected Meat and Dairy Products"); $plot->SetLegend($column_names); # Move the legend to the lower right of the plot area: $plot->SetLegendPixels(700, 300); $plot->SetDataValues($data); $plot->SetDataType('text-data-yx'); $plot->SetPlotType('stackedbars'); $plot->SetXTitle('Pounds Consumed Per Capita'); # Show data value labels: $plot->SetXDataLabelPos('plotstack'); # Rotate data value labels to 90 degrees: $plot->SetXDataLabelAngle(90); # Format the data value labels with 1 decimal place: $plot->SetXDataLabelType('data', 1); # Specify a whole number for the X tick interval: $plot->SetXTickIncrement(20); # Disable the Y tick marks: $plot->SetYTickPos('none'); $plot->DrawGraph();
function guifi_stats_chart06() { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/'; if (isset($_GET['width'])) { $gwidth = $_GET['width']; } else { $gwidth = 500; } if (isset($_GET['height'])) { $gheight = $_GET['height']; } else { $gheight = 450; } $today = getdate(); $year = $today[year]; $month = $today[mon]; $month = $month - 12; $n = 0; $tot = 0; if ($month < 1) { $year = $year - 1; $month = 12 + $month; } $datemin = mktime(0, 0, 0, $month, 1, $year); if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "0") { $zone_id = "3671"; } } else { $zone_id = "3671"; } $azone = array(); $avalue = array(); $azone[$zone_id] = array($zone_id); $achilds = array_keys(guifi_zone_childs_tree($zone_id, 1)); foreach ($achilds as $key => $child) { if ($child != $zone_id) { $azone[$child] = array(); $avalue[$child] = 0; $aschilds = guifi_zone_childs($child); foreach ($aschilds as $skey => $schild) { array_push($azone[$child], $schild); } } } $vsql = "select COUNT(*) as num, zone_id\n from {guifi_location}\n where timestamp_created >= " . $datemin . " and status_flag='Working' "; if ($zone_id != "0") { $achilds = guifi_zone_childs($zone_id); $v = ""; foreach ($achilds as $key => $child) { if ($v == "") { $v .= "zone_id=" . $child; } else { $v .= " or zone_id=" . $child; } } $vsql .= "AND (" . $v . ") "; } $vsql .= "GROUP BY zone_id "; $result = db_query($vsql); while ($record = db_fetch_object($result)) { foreach ($azone as $key => $grupzone) { if (in_array($record->zone_id, $grupzone)) { $avalue[$key] = $avalue[$key] + $record->num; } } } foreach ($avalue as $key => $value) { if ($value != 0) { $data[] = array(guifi_get_zone_name($key), $value); $tot = $tot + $value; } } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetImageBorderType('plain'); $plot->SetFileFormat('png'); $plot->SetPlotType("pie"); $plot->SetDataType("text-data-single"); $plot->SetDataValues($data); $plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'brown', 'lavender', 'pink', 'gray', 'orange')); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); $plot->SetFontTTF('legend', 'Vera.ttf', 7); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Last year')); } else { $plot->SetTitle("guifi.net \n" . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Last year')); } } $plot->SetShading(1); $plot->SetLabelScalePosition(0.45); $plot->SetLegendStyle("left", "left"); $plot->SetLegendPixels(0, 0); foreach ($data as $row) { $plot->SetLegend(implode(': ', $row)); } $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
<?php # $Id$ # Testing phplot - Fix for SetPlotAreaPixels with pie charts. require_once 'phplot.php'; $data = array(); $legend = array(); for ($i = 0; $i < 15; $i++) { $data[] = array('', 10 + $i); $legend[] = "A very long label for set {$i}"; } $p = new PHPlot(800, 500); $p->SetPlotAreaPixels(240, 20, 795, 495); $p->SetLegendPixels(5, 40); $p->SetLegend($legend); $p->SetTitle("Pie chart, SetPlotAreaPixels, Long Labels"); $p->SetDataType('text-data-single'); $p->SetDataValues($data); $p->SetPlotType('pie'); # Color background so we can see what's what: $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('gray'); $p->DrawGraph();
function solicitudes_reparacion_por_operario($id_operario, $año) { $this->loadModel('ReparacionSolicitud'); $this->loadModel('Funcionario'); $meses = $this->ReparacionSolicitud->query("SELECT MONTH(archivada) AS mes FROM reparacion_solicitudes WHERE estado='a' AND ejecutada=1 AND YEAR(archivada)=" . $año . " GROUP BY MONTH(archivada)"); if (!empty($meses)) { // Inicializamos el arreglo en ceros (para los meses ke no tienen solicitudes). $total = array(); for ($i = 1; $i <= 12; $i++) { $total[$i][0][0] = array('cuenta' => 0); } foreach ($meses as $mes) { $cant_solicitudes = $this->ReparacionSolicitud->query("SELECT COUNT(*) AS cuenta FROM reparacion_solicitudes WHERE id_funcionario=" . $id_operario . " AND estado='a' AND ejecutada=1 AND YEAR(archivada)=" . $año . " AND MONTH(archivada)=" . $mes[0]['mes']); $total[$mes[0]['mes']] = $cant_solicitudes; } if (!empty($total)) { $operario = $this->Funcionario->find('first', array('conditions' => array('Funcionario.id' => $id_operario), 'fields' => array('Funcionario.nombre'))); foreach ($total as $mes => $arreglo_mes) { $arreglo_plot[] = array($this->meses[$mes], $arreglo_mes[0][0]['cuenta']); } $plot = new PHPlot(890, 450); $plot->SetDataValues($arreglo_plot); $plot->SetDataType('text-data'); // Fuentes $plot->SetUseTTF(true); $plot->SetFontTTF('legend', 'FreeSans.ttf', 9); $plot->SetFontTTF('title', 'FreeSans.ttf', 14); $plot->SetFontTTF('y_label', 'FreeSans.ttf', 10); $plot->SetFontTTF('x_label', 'FreeSans.ttf', 10); $plot->SetFontTTF('y_title', 'FreeSans.ttf', 14); // Titulos $plot->SetTitle("\nSolicitudes de reparación\natendidas por " . mb_convert_case($operario['Funcionario']['nombre'], MB_CASE_TITLE, "UTF-8")); $plot->SetXTitle('AÑO ' . $año); $plot->SetYTitle('# SOLICITUDES'); // Etiquetas $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetDrawXGrid(true); // Leyenda $leyenda = array('Solicitudes de Reparación'); $plot->SetLegend($leyenda); $plot->SetLegendPixels(703, 0); $plot->SetPlotType('bars'); $plot->SetShading(7); $plot->DrawGraph(); } } }
// plotleft, plotright, both, full, none $graph->SetBackgroundColor($stat['background_color']); if ($stat['graphtype'] == 'bars') { $graph->SetShading(0); $graph->SetPlotAreaWorld(NULL, 0); } if (count($stat['legend']) > 0) { foreach ($stat['legend'] as $key => $val) { if (strlen($val) > 23) { $stat['legend'][$key] = substr($val, 0, 20) . '...'; } } $graph->SetLegend($stat['legend']); } if ($stat['legend_x'] && $stat['legend_y']) { $graph->SetLegendPixels($stat['legend_x'], $stat['legend_y']); } if ($stat['graphtype'] == 'pie') { $graph->SetPlotAreaPixels(150, 0, $stat['xsize'], $stat['ysize']); $graph->SetLegendPixels(1, 30); $graph->SetShading(0); if ($stype == 'experience_avg_experimentclass') { $graph->SetPieLabelType('value'); } } $graph->SetTitle($stat['title']); if ($stat['xtitle']) { $graph->SetXTitle($stat['xtitle'], 'plotdown'); } // plotup, plotdown, both, none if ($stat['ytitle']) {
$p->SetXTitle('X Axis Title'); $p->SetYTitle('Y Axis Title'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('PeachPuff'); $p->SetBackgroundColor('lavender'); $p->SetImageBorderType('solid'); $p->SetImageBorderColor('navy'); $p->SetImageBorderWidth(3); $p->SetPlotBorderType('full'); $p->SetLegend(array('Path A', 'Path B', 'Path C', 'Path D')); switch ($legend_positioning) { case 'world': $p->SetLegendWorld(0.1, 35); break; case 'pixels': $p->SetLegendPixels(50, 50); break; case 'plotrelative': # This places the upper left corner of the legend box at an offset of # (5,5) from the upper left corner of the plot area. $p->SetLegendPosition(0, 0, 'plot', 0, 0, 5, 5); break; # No default: Default is to not position the legend and let it default. } # Draw n_across * n_down plots: $plot_area_y1 = $plot_area_margin; for ($iy = 0; $iy < $n_down; $iy++) { $plot_area_x1 = $plot_area_margin; $plot_area_y2 = $plot_area_y1 + $plot_area_height; for ($ix = 0; $ix < $n_across; $ix++) { $plot_area_x2 = $plot_area_x1 + $plot_area_width;
// For presentation in the manual $plot->SetPrintImage(False); // Defer output until the end $plot->SetTitle($title); $plot->SetPlotBgColor('gray'); $plot->SetLightGridColor('black'); // So grid stands out from background # Plot 1 $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotType('stackedbars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data1); $plot->SetYTitle($y_title1); # Set and position legend #1: $plot->SetLegend($legend1); $plot->SetLegendPixels(5, 30); # Set margins to leave room for plot 2 Y title on the right. $plot->SetMarginsPixels(120, 120); # Specify Y range of these data sets: $plot->SetPlotAreaWorld(NULL, 0, NULL, 5000); $plot->SetYTickIncrement(500); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); # Format Y tick labels as integers, with thousands separator: $plot->SetYLabelType('data', 0); $plot->DrawGraph(); # Plot 2 $plot->SetDrawPlotAreaBackground(False); // Cancel background $plot->SetDrawYGrid(False); // Cancel grid, already drawn