function make_plot($plot_type, $data_type, $nx, $ny) { $plot = new PHPlot(1280, 1024); $plot->SetPrintImage(False); $plot->SetFailureImage(False); $plot->SetDataType($data_type); $plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, 100)); $plot->SetPlotType($plot_type); $plot->SetTitle("Serialize/Unserialize Tests\n{$plot_type} - {$data_type}"); $plot->SetXTickIncrement(5); $plot->SetYTickIncrement(10); $plot->SetPlotBorderType('full'); $plot->SetDrawXGrid(True); $plot->SetDrawYGrid(True); $plot->SetXTitle('X Axis Title'); $plot->SetYTitle('Y Axis Title'); # Select data labels or tick labels based on data type: if ($data_type == 'data-data') { $plot->SetXDataLabelPos('none'); $plot->SetXTickLabelPos('plotdown'); $plot->SetXTickPos('plotdown'); } elseif ($data_type == 'text-data') { $plot->SetXDataLabelPos('plotdown'); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); } elseif ($data_type == 'data-data-yx') { $plot->SetYDataLabelPos('none'); $plot->SetYTickLabelPos('plotleft'); $plot->SetYTickPos('plotleft'); } elseif ($data_type == 'text-data-yx') { $plot->SetYDataLabelPos('plotleft'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); } return $plot; }
<?php # PHPlot Example: Linepoints plot with Data Value Labels require_once 'phplot.php'; $data = array(array('1995', 135), array('1996', ''), array('1997', ''), array('1998', ''), array('1999', ''), array('2000', 225), array('2001', ''), array('2002', ''), array('2003', 456), array('2004', 420), array('2005', 373), array('2006', 300), array('2007', 255), array('2008', 283)); $plot = new PHPlot(800, 600); $plot->SetImageBorderType('plain'); // Improves presentation in the manual $plot->SetPlotType('linepoints'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle("US Federal Emergency Food Assistance, 1995 - 2008\n" . "(in \$ millions)"); # Turn on Y data labels: $plot->SetYDataLabelPos('plotin'); # Turn on X data label lines (drawn from X axis up to data point): $plot->SetDrawXDataLabelLines(True); # With Y data labels, we don't need Y ticks, Y tick labels, or grid lines. $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); $plot->SetDrawYGrid(False); # X tick marks are meaningless with this data: $plot->SetXTickPos('none'); $plot->SetXTickLabelPos('none'); $plot->DrawGraph();
} # Create a PHPlot object which will make an 800x400 pixel image: $p = new PHPlot(800, 400); # Use TrueType fonts: //$p->SetDefaultTTFont('./arial.ttf'); # Set the main plot title: $p->SetTitle('PHPlot Customer Satisfaction (estimated)'); # Select the data array representation and store the data: $p->SetDataType('text-data'); $p->SetDataValues($data); # Select the plot type - bar chart: $p->SetPlotType('bars'); # Define the data range. PHPlot can do this automatically, but not as well. $p->SetPlotAreaWorld(0, 0, 9, 100); # Select an overall image background color and another color under the plot: $p->SetBackgroundColor('#ffffcc'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('#ffffff'); # Draw lines on all 4 sides of the plot: $p->SetPlotBorderType('full'); # Set a 3 line legend, and position it in the upper left corner: $p->SetLegend(array('Features', 'Bugs', 'Happy Users')); $p->SetLegendWorld(0.1, 95); # Turn data labels on, and all ticks and tick labels off: $p->SetXDataLabelPos('plotdown'); $p->SetXTickPos('none'); $p->SetXTickLabelPos('none'); $p->SetYTickPos('none'); $p->SetYTickLabelPos('none'); # Generate and output the graph now: $p->DrawGraph();
$graph->SetDrawYGrid(FALSE); break; case 'y': $graph->SetDrawXGrid(FALSE); $graph->SetDrawYGrid(TRUE); break; case 'both': $graph->SetDrawXGrid(TRUE); $graph->SetDrawYGrid(TRUE); break; case 'none': $graph->SetDrawXGrid(FALSE); $graph->SetDrawYGrid(FALSE); } $graph->SetXTickLabelPos($which_xtick_label_pos); $graph->SetYTickLabelPos($which_ytick_label_pos); $graph->SetXDataLabelPos($which_xdata_label_pos); $graph->SetYDataLabelPos($which_ydata_label_pos); // Please remember that angles other than 90 are taken as 0 when working fith fixed fonts. $graph->SetXLabelAngle($which_xlabel_angle); $graph->SetYLabelAngle($which_ylabel_angle); //$graph->SetLineStyles(array("dashed","dashed","solid","solid")); $graph->SetPointShape($which_point); $graph->SetPointSize($which_point_size); $graph->SetDrawBrokenLines($which_broken); // Some forms in format_chart.php don't set this variable, suppress errors. @$graph->SetErrorBarShape($which_error_type); $graph->SetXAxisPosition($which_xap); $graph->SetYAxisPosition($which_yap); $graph->SetPlotBorderType($which_btype); if ($maxy_in) {
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(); } } }
# this script. The parameters are shown in the defaults array below: if (!isset($tp)) { $tp = array(); } $tp = array_merge(array('title' => 'Tick Count:', 'xmin' => 0, 'xmax' => 98, 'ymin' => 0, 'ymax' => 55, 'xti' => 10, 'yti' => 10), $tp); require_once 'phplot.php'; # The data points don't matter at all. The range is set with SetPlotAreaWorld. $data = array(array('', 0, 0), array('', 1, 1)); $p = new PHPlot(); $subtitle = " World: ({$tp['xmin']}, {$tp['ymin']}) :" . " ({$tp['xmax']}, {$tp['ymax']})" . " Tickstep: ({$tp['xti']}, {$tp['yti']})"; $p->SetTitle($tp['title'] . $subtitle); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXDataLabelPos('none'); $p->SetXTitle('X'); $p->SetYTitle('Y'); $p->SetPlotAreaWorld($tp['xmin'], $tp['ymin'], $tp['xmax'], $tp['ymax']); $p->SetXTickIncrement($tp['xti']); $p->SetYTickIncrement($tp['yti']); #$p->SetSkipTopTick(False); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); # Axes on all sides: $p->SetXTickPos('both'); $p->SetXTickLabelPos('both'); $p->SetYTickPos('both'); $p->SetYTickLabelPos('both'); $p->SetPlotBorderType('full'); $p->SetPlotType('lines'); $p->DrawGraph();
function guifi_stats_chart03() { 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; } if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "3671") { $zone_id = "0"; } } else { $zone_id = "0"; } $vsql = "select COUNT(*) as num, month(FROM_UNIXTIME(timestamp_created)) as mes\n from {guifi_location} where 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 MONTH(FROM_UNIXTIME(timestamp_created)) "; $result = db_query($vsql); $tot = 0; $valor = 0; while ($record = db_fetch_object($result)) { $tot += $record->num; $data[] = array("{$record->mes}", $record->num); } foreach ($data as &$dat) { $dat[1] = $dat[1] * 100 / $tot; } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("text-data"); $plot->SetDataValues($data); $plot->SetPlotType("bars"); //$plot->SetYTickIncrement(10); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetTickLength(0); $plot->SetXTickPos('none'); $plot->SetYTickPos('none'); $plot->SetDrawYGrid(FALSE); $plot->SetYTickLabelPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetTickColor('grey'); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Monthly average')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Monthly average')); } } $plot->SetXTitle(t('Months')); $plot->SetYTitle(t('% Working nodes')); $plot->SetXDataLabelPos('plotdown'); $plot->SetXLabelAngle(0); $plot->SetYLabelType('data', 2); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor('DimGrey'); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
$data = array(array('A', 0, 0, 1, 0, 0, 0, 0), array('B', 1, 1, 1, 1, 2, 1, 1), array('H', 7, 7, 1, 1, 14, 1, 1), array('D', 3, 3, 1, 0, 6, 0, 0), array('F', 5, 5, 1, 1, 10, 1, 0), array('C', 2, 2, 0, 1, 4, 1, 1), array('G', 6, 6, 1, 1, 12, 0, 1), array('E', 4, 4, 0, 0, 8, 1, 1)); } else { fwrite(STDERR, "Error: Unknown data type or not decoded: {$data}-type\n"); exit(1); } $p = new PHPlot(800, 800); $p->SetTitle("Testing PHPlot ({$plot_type}, {$data_type})"); $p->SetDataType($data_type); $p->SetDataValues($data); $p->SetPlotType($plot_type); if ($horizontal) { $p->SetXTitle('X Axis - Dependent variable'); $p->SetYTitle('Y Axis - Independent variable'); $p->SetXDataLabelPos('plotin'); // Tick labels left, Axis Data labels right, so both can be seen. $p->SetYTickLabelPos('plotleft'); $p->SetYDataLabelPos('plotright'); } else { $p->SetXTitle('X Axis - Independent variable'); $p->SetYTitle('Y Axis - Dependent variable'); $p->SetYDataLabelPos('plotin'); // Tick labels below, Axis Data labels above, so both can be seen. $p->SetXTickLabelPos('plotdown'); $p->SetXDataLabelPos('plotup'); } # Customizations for error plots: if ($error_bars) { # With error plots, the default 90 degree position for data value labels # will overlay the error bar, so move them to 45 degrees: $p->data_value_label_angle = 45; # Turn off the grid lines, so the error bars are move visible.
$title = "Horizontal Bar Chart Y Axis Range Test: {$nx} Bars, {$ny} Data Sets"; } # Build a data array: $data = array(); for ($x = 0; $x < $nx; $x++) { $row = array("={$x}="); for ($y = 0; $y < $ny; $y++) { $row[] = $x + $y + 10; } $data[] = $row; } $p = new PHPlot(800, 800); $p->SetTitle($title); $p->SetDataType($data_type); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetShading(0); # Note: In a typical bar plot, X axis tick labels would be off and only # data labels would be shown, but for test purposes both are on here, with # tick labels on opposite side. if ($horizontal) { $p->SetYTickPos('both'); $p->SetYTickLabelPos('plotright'); $p->SetYDataLabelPos('plotleft'); } else { $p->SetXTickPos('both'); $p->SetXTickLabelPos('plotup'); $p->SetXDataLabelPos('plotdown'); } $p->SetPlotBorderType('full'); $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, plotin, none // Remember that angles other than 90 are taken as 0 when working with fixed fonts. if (isset($stat['x_label_angle'])) { $graph->SetXLabelAngle($stat['x_label_angle']); } else { $graph->SetXLabelAngle(0); } $graph->SetYLabelAngle(0); if (!(isset($stat['tick_increment_y']) && $stat['tick_increment_y'])) { $stat['tick_increment_y'] = stats__get_y_increment($stat['data']); } $graph->SetYTickIncrement($stat['tick_increment_y']); $graph->SetXTickLabelPos('plotdown'); // plotup, plotdown, both, xaxis, none $graph->SetYTickLabelPos('both'); // plotleft, plotright, both, yaxis, none $graph->SetXTickPos('plotdown'); // plotup, plotdown, both, xaxis, none $graph->SetYTickPos('both'); // plotleft, plotright, both, yaxis, none //Set some data if ($stat['reverse_data']) { $data = array_reverse($stat['data']); } else { $data = $stat['data']; } $graph->SetDataValues($data); $graph->SetXTickLabelPos('none'); $graph->SetXTickPos('none'); //echo '<pre>';
# <=12 13-17 17-28 30-39 40-54 >=55 $data = array(array('Cherry', 1, 1, 2, 2, 4, 3, 3, 4, 3, 5, 5, 6, 6), array('Apple', 2, 1, 9, 2, 7, 3, 4, 4, 7, 5, 3, 6, 7), array('Pear', 3, '', 2, 2, 2, 3, 3, 4, 4, 5, 3, 6, 2), array('Grape', 4, 1, 8, 2, 5, 3, 5, 4, 6, 5, 3, 6, 4), array('Kiwi', 5, '', 0, 2, 3, 3, 4, 4, 4, 5, 5, 6, 2), array('Banana', 6, 1, 5, 2, 4, 3, 6, 4, 3, 5, 3, 6, 4)); $plot = new PHPlot(600, 600); $plot->SetTitle("Flavor Preference By Age Group"); $plot->SetDataType('data-data-xyz'); $plot->SetDataValues($data); $plot->SetPlotType('bubbles'); $plot->SetDataColors('yellow'); // Use same color for all data sets $plot->SetDrawPlotAreaBackground(True); $plot->SetPlotBgColor('plum'); $plot->SetLightGridColor('red'); // Change grid color to make it visible $plot->SetImageBorderType('plain'); $plot->SetPlotBorderType('full'); $plot->SetXTickIncrement(1); // For grid line spacing $plot->SetYTickIncrement(1); $plot->SetPlotAreaWorld(0, 0, 6.5, 6.5); # Establish the handler for the Y label text: $plot->SetYLabelType('custom', 'get_label', $y_labels); $plot->SetXTickPos('both'); // Tick marks on both sides $plot->SetYTickPos('both'); // Tick marks on top and bottom too $plot->SetXDataLabelPos('both'); // X axis data labels top and bottom $plot->SetYTickLabelPos('both'); // Y axis labels left and right $plot->SetDrawXGrid(True); $plot->DrawGraph();
$p = new PHPlot(400, 300); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotAreaWorld(0, 0, 4, 10); $p->SetXTickIncrement(1); $p->SetYTickIncrement(1); $p->SetPlotBorderType('full'); $p->SetXDataLabelPos($tp['xdatalabel']); $p->SetXTickLabelPos($tp['xticklabel']); if (isset($tp['xtick'])) { $p->SetXTickPos($tp['xtick']); } else { $p->SetXTickPos($tp['xticklabel']); } $p->SetYTickLabelPos($tp['yticklabel']); $p->SetYTickPos($tp['yticklabel']); $p->SetXTitle('X TITLE'); $p->SetYTitle('Y TITLE'); # Tick skip tests: if (isset($tp['skiptick'])) { $s = $tp['skiptick']; $n = strlen($s); for ($i = 0; $i < $n; $i++) { switch ($s[$i]) { case 'T': $p->SetSkipTopTick(True); break; case 'B': $p->SetSkipBottomTick(True); break;
$p->SetXDataLabelAngle($tp['xd_angle']); } if (isset($tp['x_type'])) { $p->SetXLabelType($tp['x_type'], $tp['x_type_arg']); } if (isset($tp['xd_type'])) { $p->SetXDataLabelType($tp['xd_type'], $tp['xd_type_arg']); } if (isset($tp['xt_pos'])) { $p->SetXTickLabelPos($tp['xt_pos']); } if (isset($tp['xd_pos'])) { $p->SetXDataLabelPos($tp['xd_pos']); } # Options: Y if (isset($tp['y_angle'])) { $p->SetYLabelAngle($tp['y_angle']); } if (isset($tp['yd_angle'])) { $p->SetYDataLabelAngle($tp['yd_angle']); } if (isset($tp['y_type'])) { $p->SetYLabelType($tp['y_type'], $tp['y_type_arg']); } if (isset($tp['yd_type'])) { $p->SetYDataLabelType($tp['yd_type'], $tp['yd_type_arg']); } if (isset($tp['yt_pos'])) { $p->SetYTickLabelPos($tp['yt_pos']); } $p->DrawGraph();